VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ14²¿·Ö
°´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·ҳ£¬°´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ£¬°´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿£¡
¡ª¡ª¡ª¡ªÎ´ÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡
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¡¡TestSimpleAddition£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡result¡¡As¡¡Integer¡¡=¡¡Operations¡£Add£¨1£»¡¡2£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡£¨total¡¡¡¡3£©¡¡Then¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Oops¡¡1¡¡and¡¡2¡¡does¡¡not¡¡equal¡¡3¡¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡
¡¡¡¡¡¡¡¡End¡¡Sub¡¡
¡¡¡¡¡¡¡¡Sub¡¡Main£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡TestSimpleAddition£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£ReadKey£¨£©¡¡
¡¡¡¡¡¡¡¡End¡¡Sub¡¡
End¡¡Module¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡60¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
38¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Press¡¡Ctrl£«F5¡¡to¡¡test¡¡the¡¡calculation¡£¡¡When¡¡executed£»¡¡the¡¡testing¡¡console¡¡application¡¡calls¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡test¡¡method¡¡TestSimpleAddition£¨£©£»¡¡which¡¡calls¡¡and¡¡verifies¡¡the¡¡functionality¡¡of¡¡the¡¡Calculator¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡class¡¡library¡£¡¡If¡¡everything¡¡works£»¡¡the¡¡message¡¡will¡¡not¡¡appear¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡Recall¡¡that¡¡the¡¡Main£¨£©¡¡method¡¡is¡¡where¡¡a¡¡project¡¡begins¡¡its¡¡operation¡£¡¡To¡¡make¡¡an¡¡application¡¡do¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡something£»¡¡you¡¡must¡¡add¡¡code¡¡to¡¡its¡¡Main£¨£©¡¡method¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡To¡¡see¡¡that¡¡the¡¡test¡¡also¡¡fails£»¡¡change¡¡the¡¡Add£¨£©¡¡method¡¡as¡¡follows£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Shared¡¡Function¡¡Add£¨ByVal¡¡number1¡¡As¡¡Integer£»¡¡ByVal¡¡number2¡¡As¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Integer£©¡¡As¡¡Integer¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡number1¡¡*¡¡number2¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Function¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Now¡¡rerun¡¡the¡¡program£»¡¡and¡¡you¡¯ll¡¡see¡¡the¡¡failure¡¡message¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡THE¡¡DEVELOPMENT¡¡CYCLE¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡So¡¡far¡¡in¡¡this¡¡chapter£»¡¡we¡¯ve¡¡dealt¡¡with¡¡three¡¡pieces¡¡of¡¡code£º¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡¡¡The¡¡code¡¡segment¡¡that¡¡implements¡¡the¡¡Add£¨£©¡¡method¡¡performs¡¡the¡¡calculation¡¡operation¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡¡¡The¡¡code¡¡that¡¡represents¡¡a¡¡caller£»¡¡which¡¡could¡¡be¡¡either¡¡the¡¡Windows¡¡application¡¡or¡¡the¡¡console¡¡appli
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡cation£»¡¡is¡¡considered¡¡production¡¡code¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡¡¡The¡¡code¡¡that¡¡contains¡¡the¡¡production¡¡code¡¡with¡¡some¡¡verification¡¡routines¡¡represents¡¡testing¡¡code¡£¡¡The¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡testing¡¡code¡¡is¡¡important¡¡because£»¡¡if¡¡the¡¡ponent¡¡implementation¡¡is¡¡altered£»¡¡you¡¡need¡¡to¡¡rerun¡¡only¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡testing¡¡code¡¡to¡¡make¡¡sure¡¡everything¡¡works¡¡as¡¡it¡¡should¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡These¡¡three¡¡pieces¡¡of¡¡code¡¡have¡¡demonstrated¡¡a¡¡plete¡¡development¡¡cycle¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Testing¡¡the¡¡Addition¡¡of¡¡Two¡¡Very¡¡Large¡¡Numbers¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡code¡¡and¡¡projects¡¡have¡¡been¡¡organized£»¡¡but¡¡we¡¯re¡¡missing¡¡some¡¡tests¡£¡¡The¡¡current¡¡test¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡adds¡¡two¡¡simple¡¡numbers¡£¡¡Another¡¡test¡¡could¡¡be¡¡to¡¡add¡¡two¡¡really¡¡big¡¡numbers£»¡¡such¡¡as¡¡2¡¡billion¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡2¡¡billion¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡code¡¡to¡¡test¡¡the¡¡addition¡¡of¡¡two¡¡really¡¡big¡¡numbers¡¡is¡¡shown¡¡in¡¡Figure¡¡2¡11¡£¡¡Add¡¡this¡¡to¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Module1¡£vb¡¡in¡¡the¡¡TestCalculator¡¡project¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡61¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡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¡¡¡¡39¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Addition¡¡result¡¡is¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡stored¡¡in¡¡a¡¡variable¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2¡¡billion¡¡added¡¡to¡¡2¡¡billion¡¡
¡¡¡¡Public¡¡Sub¡¡TestReallyBigNumbers£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡total¡¡As¡¡Integer¡¡=¡¡Operations¡£Add£¨2000000000£»¡¡2000000000£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡If¡¡£¨total¡¡¡¡4000000000£©¡¡Then¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Error¡¡found£¨¡¨¡¡&¡¡total¡¡&¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¨£©¡¡should¡¡have¡¡been¡¡£¨4000000000£©¡¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡
¡¡¡¡End¡¡Sub¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Verification¡¡of¡¡addition¡¡is¡¡4¡¡billion¡¡¡¡¡¡¡¡If¡¡there¡¡is¡¡an¡¡error£»¡¡a¡¡string¡¡is¡¡built¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡using¡¡concatenation¡¡techniques¡¡
Figure¡¡2¡11¡£¡¡¡¡Testing¡¡the¡¡addition¡¡of¡¡two¡¡large¡¡numbers¡¡
¡¡¡¡¡¡¡¡¡¡¡¡The¡¡test¡¡to¡¡add¡¡two¡¡very¡¡large¡¡numbers¡¡is¡¡identical¡¡to¡¡the¡¡test¡¡to¡¡add¡¡two¡¡simple¡¡numbers£»¡¡¡¡
except¡¡for¡¡the¡¡numbers¡¡themselves¡£¡¡The¡¡error¡¡message¡¡is¡¡handled¡¡a¡¡bit¡¡differently¡¡than¡¡in¡¡the¡¡¡¡
previous¡¡code£»¡¡in¡¡that¡¡it¡¡is¡¡built¡¡using¡¡concatenation¡¡techniques¡£¡¡In¡¡the¡¡example£»¡¡a¡¡string¡¡is¡¡¡¡
concatenated¡¡with¡¡an¡¡intege