Сţµç×ÓÊé > ÆäËûµç×ÓÊé > VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ) >

µÚ17ÕÂ

VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ17ÕÂ

С˵£º VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ) ×ÖÊý£º ÿҳ3500×Ö

°´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³£¬°´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ£¬°´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿£¡
¡ª¡ª¡ª¡ªÎ´ÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡




¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡another¡¡application¡¡in¡¡the¡¡next¡¡section¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Namespace¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Class¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Method¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡total¡¡As¡¡Integer¡¡=¡¡Calculator¡£Operations¡£Add£¨1£»¡¡2£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡total¡¡is¡¡an¡¡integer¡¡declared¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡¡and¡¡2¡¡are¡¡integer¡¡values£»¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡variable¡¡that¡¡stores¡¡the¡¡result¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡which¡¡represent¡¡the¡¡two¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡of¡¡the¡¡addition¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡numbers¡¡that¡¡are¡¡added¡¡together¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡2¡­7¡£¡¡¡¡The¡¡Add£¨£©¡¡method¡¡is¡¡called¡¡by¡¡referencing¡¡the¡¡namespace¡¡and¡¡class¡¡containing¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡method¡£¡¡A¡¡period¡¡is¡¡used¡¡to¡¡separate¡¡the¡¡identifiers¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡caller¡¡must¡¡do¡¡two¡¡things£º¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Reference¡¡the¡¡correct¡¡bination¡¡of¡¡namespace£»¡¡class£»¡¡and¡¡method¡¡identifiers¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Pass¡¡the¡¡correct¡¡types¡¡into¡¡the¡¡method£»¡¡as¡¡specified¡¡by¡¡the¡¡method¡¡signature¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡example£»¡¡the¡¡addition¡¡of¡¡1¡¡and¡¡2¡¡results¡¡in¡¡3£»¡¡and¡¡therefore¡¡the¡¡variable¡¡total¡¡should¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡contain¡¡the¡¡value¡¡3¡¡£¨the¡¡equal¡¡sign¡¡assigns¡¡the¡¡value¡¡returned¡¡from¡¡the¡¡method¡¡to¡¡the¡¡variable¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡on¡¡its¡¡left£©¡£¡¡I¡¡say¡¡¡°should¡¡contain¡¡the¡¡value£»¡±¡¡because¡¡when¡¡writing¡¡code£»¡¡you¡¡are¡¡not¡¡always¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡sure¡£¡¡Sometimes¡¡the¡¡code¡¡you¡¡write¡¡will¡¡be¡¡wrong¡¡because¡¡you¡¡overlooked¡¡something¡¡or¡¡forgot¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡reference¡¡something¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Look¡¡at¡¡the¡¡calling¡¡code£»¡¡and¡¡ask¡¡yourself¡¡if¡¡you¡¡are¡¡guaranteed¡¡that¡¡calling¡¡Add£¨£©¡¡with¡¡¡¡1¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡2¡¡will¡¡result¡¡in¡¡3¡£¡¡The¡¡answer¡¡is¡¡that£»¡¡as¡¡a¡¡caller£»¡¡you¡¡cannot¡¡be¡¡100£¥¡¡sure¡¡that¡¡the¡¡total¡¡variable¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡will¡¡contain¡¡3¡£¡¡Just¡¡because¡¡a¡¡box¡¡has¡¡the¡¡label¡¡¡°Dishes¡±¡¡does¡¡not¡¡necessarily¡¡mean¡¡that¡¡dishes¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡57¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡A¡¡PT¡¡E¡¡R¡¡¡¡¡¡2¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡¡£¡¡N¡¡E¡¡T¡¡¡¡N¡¡U¡¡M¡¡B¡¡E¡¡R¡¡¡¡¡¡AN¡¡D¡¡¡¡¡¡V¡¡A¡¡L¡¡U¡¡E¡¡¡¡¡¡T¡¡Y¡¡P¡¡E¡¡S¡¡¡¡35¡¡



are¡¡in¡¡the¡¡box¡£¡¡You¡¡think¡¡you¡¡know¡¡the¡¡contents£»¡¡but¡¡you¡¡cannot¡¡be¡¡100£¥¡¡sure¡¡until¡¡you¡¡open¡¡¡¡

the¡¡box¡£¡¡Likewise£»¡¡in¡¡code£»¡¡you¡¡need¡¡to¡¡look¡¡at¡¡how¡¡the¡¡Add£¨£©¡¡method¡¡is¡¡implemented¡¡to¡¡be¡¡sure¡¡¡¡

of¡¡the¡¡contents¡¡of¡¡the¡¡total¡¡variable¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡In¡¡a¡¡production¡¡coding¡¡session£»¡¡looking¡¡at¡¡the¡¡implementation¡¡code¡¡to¡¡verify¡¡it¡¡is¡¡doing¡¡¡¡

what¡¡you¡¡expect¡¡is¡¡not¡¡a¡¡feasible¡¡solution£»¡¡because¡¡that¡¡would¡¡take¡¡too¡¡much¡¡time¡¡and¡¡be¡¡¡¡

pletely¡¡unreliable¡£¡¡The¡¡only¡¡real¡¡solution¡¡is¡¡to¡¡write¡¡test¡¡code¡£¡¡¡¡



Writing¡¡Code¡¡to¡¡Test¡¡the¡¡Add£¨£©¡¡Method¡¡



Test¡¡code¡¡is¡¡caller¡¡code¡¡that¡¡passes¡¡parameters¡¡with¡¡targeted¡¡values¡¡and¡¡expects¡¡a¡¡targeted¡¡¡¡

answer¡£¡¡If¡¡the¡¡caller¡¡does¡¡not¡¡get¡¡the¡¡targeted¡¡answer£»¡¡then¡¡the¡¡implementation¡¡of¡¡the¡¡tested¡¡¡¡

method¡¡is¡¡wrong¡£¡¡Figure¡¡2¡­8¡¡shows¡¡sample¡¡caller¡¡code¡¡that¡¡tests¡¡the¡¡Add£¨£©¡¡operation¡¡£¨we¡¯ll¡¡add¡¡¡¡

this¡¡to¡¡a¡¡project¡¡next£©¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Targeted¡¡caller¡¡code¡¡that¡¡adds¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡¡and¡¡2¡¡and¡¡assigns¡¡the¡¡result¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡the¡¡variable¡¡total¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡total¡¡As¡¡Integer¡¡=¡¡Operations¡£Add£¨1£»¡¡2£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡£¨total¡¡¡¡3£©¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Oops¡¡1¡¡add¡¡2¡¡does¡¡not¡¡equal¡¡3¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡



¡¡¡¡¡¡Targeted¡¡testing¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡targeted¡¡testing¡¡fails£»¡¡the¡¡

¡¡¡¡¡¡¡¡of¡¡the¡¡variable¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡text¡¡¡°Oops¡­¡±¡¡is¡¡generated£»¡¡

¡¡¡¡¡¡total£»¡¡paring¡¡it¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡indicating¡¡an¡¡error¡¡

¡¡¡¡¡¡¡¡¡¡to¡¡the¡¡value¡¡3¡¡



Figure¡¡2¡­8¡£¡¡¡¡Testing¡¡the¡¡Add£¨£©¡¡method¡¡



¡¡¡¡¡¡¡¡¡¡¡¡The¡¡calling¡¡code¡¡of¡¡the¡¡test¡¡bears¡¡an¡¡uncanny¡¡resemblance¡¡to¡¡the¡¡code¡¡you¡¡saw¡¡in¡¡the¡¡previous¡¡¡¡

section¡£¡¡The¡¡difference¡¡is¡¡that¡¡the¡¡test¡¡code¡¡uses¡¡targeted¡¡variables¡¡and¡¡values£»¡¡whereas¡¡the¡¡¡¡

other¡¡code¡¡could¡¡contain¡¡any¡¡variables¡¡and¡¡values¡£¡¡Another¡¡requirement¡¡of¡¡test¡¡code¡¡is¡¡to¡¡verify¡¡¡¡

the¡¡answers¡¡returned¡¡by¡¡the¡¡method¡¡with¡¡targeted¡¡responses¡£¡¡The¡¡If¡¡statement¡¡is¡¡used¡¡to¡¡check¡¡¡¡

whether¡¡the¡¡value¡¡of¡¡the¡¡variable¡¡total¡¡is¡¡equal¡¡to¡¡¡¡3¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡When¡¡writing¡¡test¡¡code£»¡¡the¡¡way¡¡the¡¡Add£¨£©¡¡method¡¡is¡¡used¡¡must¡¡be¡¡the¡¡same¡¡way¡¡the¡¡¡¡

console¡¡or¡¡Windows¡¡application¡¡uses¡¡the¡¡method¡£¡¡Otherwise£»¡¡it¡¡would¡¡be¡¡like¡¡testing¡¡a¡¡winter¡¡¡¡

tire¡¡in¡¡the¡¡middle¡¡of¡¡the¡¡Sahara¡ªfun¡¡to¡¡do¡¡but¡¡irrelevant¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡Another¡¡question¡¡related¡¡to¡¡testing¡¡has¡¡to¡¡do¡¡with¡¡the¡¡timing¡¡of¡¡tests¡£¡¡Do¡¡you¡¡create¡¡the¡¡¡¡

tests¡¡before¡¡or¡¡after¡¡implementing¡¡the¡¡Add£¨£©¡¡method£¿¡¡To¡¡get¡¡a¡¡clear¡¡understanding¡¡of¡¡the¡¡problem£»¡¡¡¡

imagine¡¡the¡¡development¡¡of¡¡a¡¡tire¡£¡¡Do¡¡you¡¡define¡¡the¡¡tests¡¡for¡¡the¡¡tire¡¡before¡¡or¡¡after¡¡the¡¡tire¡¡has¡¡¡¡

been¡¡developed£¿¡¡Most¡¡likely£»¡¡the¡¡answer¡¡is¡¡before£»¡¡during£»¡¡and¡¡after¡¡development¡£¡¡This¡¡is¡¡an¡¡¡¡

important¡¡consideration¡¡when¡¡developing¡¡software¡£¡¡Tests¡¡are¡¡written¡¡before£»¡¡during£»¡¡and¡¡after¡¡¡¡

implementation£»¡¡as¡¡follows£º¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡58¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

36¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡2¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡¡£¡¡N¡¡E¡¡T¡¡¡¡N¡¡U¡¡M¡¡B¡¡E¡¡R¡¡¡¡¡¡A¡¡N¡¡D¡¡¡¡¡¡V¡¡A¡¡L¡¡U¡¡E¡¡¡¡¡¡T¡¡Y¡¡P¡¡E¡¡S¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡You¡¡develop¡¡tests¡¡before¡¡implementing¡¡the¡¡Add£¨£©¡¡method¡¡to¡¡get¡¡an¡¡idea¡¡of¡¡what¡¡name

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡spaces£»¡¡classes£»¡¡and¡¡methods¡¡you¡¡will¡¡be¡¡defining¡£¡¡The¡¡definition¡¡of¡¡the¡¡different¡¡items¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡gives¡¡the¡¡developer¡¡an¡¡idea¡¡of¡¡how¡¡the¡¡items¡¡will¡¡be¡¡used¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡You¡¡develop¡¡tests¡¡during¡¡the¡¡implementation¡¡of¡¡the¡¡Add£¨£©¡¡method¡¡to¡¡verify¡¡that¡¡your¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡source¡¡code¡¡implementation¡¡is¡¡on¡¡the¡¡right¡¡track¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡You¡¡develop¡¡tests¡¡after¡¡the¡¡implementation¡¡of¡¡the¡¡Add£¨£©¡¡method¡¡as¡¡an¡¡exhaustive¡¡measure¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡make¡¡sure¡¡you¡¯ve¡¡dotted¡¡the¡¡i¡¯s¡¡and¡¡crossed¡¡the¡¡t¡¯s¡¡in¡¡the¡¡implementation¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Adding¡¡a¡¡Test¡¡Project¡¡to¡¡Your¡¡Solution¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡When¡¡writing¡¡test¡¡routines£»¡¡you¡¡will¡¡need¡¡to¡¡organize¡¡the¡¡source¡¡code£»¡¡and¡¡that¡¡means¡¡figuring¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡out¡¡to¡¡which¡¡project¡¡the¡¡tests¡¡are¡¡added¡£¡¡For¡¡the¡¡calculator¡¡application£»¡¡you¡¡could¡¡place¡¡the¡¡test¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡routines¡¡within¡¡the¡¡Calculator¡¡class¡¡library¡£¡¡However£»¡¡doing¡¡that¡¡is¡¡not¡¡the¡¡proper¡¡approach¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡due¡¡to¡¡distribution¡¡of¡¡the¡¡class¡¡library¡¡and¡¡correct¡¡testing¡¡context¡£¡¡Remember¡¡that¡¡the¡¡test¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡routines¡¡must¡¡be¡¡identical¡¡to¡¡how¡¡the¡¡code¡¡will¡¡be¡¡used¡£¡¡Thus£»¡¡the¡¡appropriate¡¡place¡¡for¡¡the¡¡test¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡routines¡¡is¡¡in¡¡their¡¡own¡¡application¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡ideal¡¡approach¡¡is¡¡to¡¡create¡¡another¡¡application¡¡that¡¡represents¡¡the¡¡tests¡£¡¡Figure¡¡2¡­5¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡illustrated¡¡how¡¡a¡¡Windows¡¡and¡¡console¡¡application¡¡could¡¡use¡¡the¡¡Calculator¡¡class¡¡library¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡2¡­9¡¡adds¡¡the¡¡testing¡¡console¡¡application¡¡that¡¡also¡¡uses¡¡the¡¡class¡¡library¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡2¡­9¡£¡¡Adding¡¡the¡¡testing¡¡console¡¡application¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡testing¡¡console¡¡application¡¡is¡¡like¡¡the¡¡console¡¡application¡¡created¡¡in¡¡Chapter¡¡1£»¡¡and¡¡it¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡references¡¡the¡¡Calculator¡¡class¡¡library¡£¡¡Both¡¡projects¡¡should¡¡be¡¡part¡¡of¡¡the¡¡Calculator¡¡solution¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Go¡¡ahead¡¡and¡¡add¡¡the¡¡TestCalculator¡¡project¡¡to¡¡the¡¡Calculator¡¡solution¡£¡¡Remember¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡add¡¡a¡¡reference¡¡to¡¡the¡¡Calculator¡¡class¡¡library¡¡£¨right¡­click¡¡TestCalculator¡¡and¡¡choose¡¡Add¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Reference¡¡¡¡Projects¡¡¡¡Calculator£©¡£¡¡Remember¡¡to¡¡set¡¡TestCalculator¡¡as¡¡the¡¡startup¡¡project¡¡for¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡debugging¡¡purposes¡£¡¡Figure¡¡2¡­10¡¡shows¡¡the¡¡TestCalculator¡¡and¡¡Calculator¡¡projects¡¡in¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Solution¡¡Explorer¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡59¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡A¡¡PT¡¡E¡¡R¡¡¡¡¡¡2¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡¡£¡¡N¡¡E¡¡T¡¡¡¡N¡¡U¡¡M¡¡B¡¡E¡¡R¡¡¡¡¡¡AN¡¡D¡¡¡¡¡¡V¡¡A¡¡L¡¡U¡¡E¡¡¡¡¡¡T¡¡Y¡¡P¡¡E¡¡S¡¡¡¡37¡¡



Figure¡¡2¡­10¡£¡¡Solution¡¡Explorer¡¡showing¡¡the¡¡testing¡¡console¡¡application¡¡and¡¡Calculator¡¡¡¡

class¡¡library¡¡



Testing¡¡Simple¡¡Addition¡¡



Add¡¡the¡¡boldfaced¡¡code¡¡to¡¡Module1¡£vb¡¡in¡¡the¡¡testing¡¡console¡¡project¡¡to¡¡verify¡¡the¡¡addition¡¡of¡¡1¡¡¡¡

and¡¡2¡¡£¨the¡¡¡¡operator¡¡means¡¡is¡¡not¡¡equal¡¡to£©£º¡¡



Imports¡¡Calculator¡¡



Module¡¡Module1¡¡

¡¡¡¡¡¡¡¡Public¡¡Sub¡¡TestSimpleA

·µ»ØĿ¼ ÉÏÒ»Ò³ ÏÂÒ»Ò³ »Øµ½¶¥²¿ ÔÞ£¨2£© ²È£¨2£©

Äã¿ÉÄÜϲ»¶µÄ