锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久精品午夜一区二区福利,久久久久亚洲av成人无码电影,久久毛片免费看一区二区三区http://www.shnenglu.com/tankzhouqiang/category/18742.htmlzh-cnThu, 01 Mar 2012 13:10:08 GMTThu, 01 Mar 2012 13:10:08 GMT60CppUnit蹇熷叆闂紙杞澆錛?/title><link>http://www.shnenglu.com/tankzhouqiang/archive/2012/03/01/166911.html</link><dc:creator>鍛ㄥ己</dc:creator><author>鍛ㄥ己</author><pubDate>Thu, 01 Mar 2012 12:25:00 GMT</pubDate><guid>http://www.shnenglu.com/tankzhouqiang/archive/2012/03/01/166911.html</guid><wfw:comment>http://www.shnenglu.com/tankzhouqiang/comments/166911.html</wfw:comment><comments>http://www.shnenglu.com/tankzhouqiang/archive/2012/03/01/166911.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/tankzhouqiang/comments/commentRss/166911.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/tankzhouqiang/services/trackbacks/166911.html</trackback:ping><description><![CDATA[<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">綆浠?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">嫻嬭瘯鏄蔣浠跺紑鍙戣繃紼嬩腑鏋佸叾閲嶈鐨勪竴鐜紝璇﹀敖鍛ㄥ瘑鐨勬祴璇曡兘澶熷噺灝戣蔣浠禕UG錛屾彁楂樿蔣浠跺搧璐ㄣ傛祴璇曞寘鎷崟鍏冩祴璇曘佺郴緇熸祴璇曠瓑銆傚叾涓崟鍏冩祴璇曟槸鎸囬拡瀵硅蔣浠跺姛鑳藉崟鍏冩墍浣滅殑嫻嬭瘯錛岃繖閲岀殑鍔熻兘鍗曞厓鍙互鏄竴涓被鐨勫睘鎬ф垨鑰呮柟娉曪紝嫻嬭瘯鐨勭洰鐨勬槸鐪嬭繖浜涘熀鏈崟鍏冩槸鍚﹀伐浣滄甯搞傜敱浜庡崟鍏冩祴璇曠殑鍐呭寰堝熀紜錛屽洜姝ゅ彲浠ョ湅浣滄槸嫻嬭瘯宸ヤ綔鐨勭涓鐜紝璇ラ」宸ヤ綔涓鑸敱寮鍙戜漢鍛樿嚜琛屽畬鎴愩傚鏋滄潯浠跺厑璁革紝鍗曞厓嫻嬭瘯浠g爜鐨勫紑鍙戝簲涓庣▼搴忎唬鐮佺殑寮鍙戝悓姝ヨ繘琛屻?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">铏界劧涓嶅悓紼嬪簭鐨勫崟鍏冩祴璇曚唬鐮佷笉灝界浉鍚岋紝浣嗘祴璇曚唬鐮佺殑妗嗘灦鍗撮潪甯哥浉浼鹼紝浜庢槸渚垮嚭鐜頒簡涓浜涘崟鍏冩祴璇曠被搴擄紝CppUnit渚挎槸鍏朵腑涔嬩竴銆?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">CppUnit鏄疿Unit涓殑涓鍛橈紝XUnit鏄竴涓ぇ瀹舵棌錛岃繕鍖呮嫭JUnit鍜孭ythonUnit絳夈侰ppUnit綆鍗曞疄鐢紝瀛︿範鍜屼嬌鐢ㄨ搗鏉ラ兘寰堟柟渚匡紝緗戜笂宸叉湁涓浜涙枃绔犲鍏朵綔浠嬬粛錛屼絾鏈枃鏇寸潃閲嶄簬璁茶В鍏朵腑鐨勫熀鏈蹇靛拰浣跨敤鏂規硶錛屼互甯姪鍒濇鎺ヨЕCppUnit鐨勪漢鍛樺揩閫熷叆闂ㄣ?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">瀹夎</p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鐩墠錛孋ppUnit鐨勬渶鏂扮増鏈槸1.10.2錛屼綘鍙互浠庝笅闈㈠湴鍧鑾峰彇錛?/p><a style="color: #336699; text-decoration: none; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">http://sourceforge.net/projects/cppunit</a><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">瑙e帇鍚庯紝浣犲彲浠ョ湅鍒癈ppUnit鍖呭惈濡備笅鐩綍錛?/p><pre style="word-wrap: break-word; white-space: normal; line-height: 26px; text-align: left; background-color: #f5f5f5; color: green; ">config錛?閰嶇疆鏂囦歡 contrib錛?contribution錛屽叾浠栦漢璐$尞鐨勫鍥翠唬鐮?doc錛?鏂囨。錛岄渶瑕侀氳繃doxygen宸ュ叿鐢熸垚錛屼篃鍙互鐩存帴浠巗ourceforge绔欑偣涓婁笅杞芥墦鍖呭ソ鐨勬枃妗?examples錛氱ず渚嬩唬鐮?include錛?澶存枃浠?lib錛?瀛樻斁緙栬瘧濂界殑搴?src錛?婧愭枃浠訛紝浠ュ強緙栬瘧搴撶殑宸ョ▼絳?/pre><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鐒跺悗鎵撳紑src鐩綍涓嬬殑CppUnitLibraries宸ョ▼錛屾墽琛宐uild/batch build錛岀紪璇戞垚鍔熺殑璇濓紝鐢熸垚鐨勫簱鏂囦歡灝嗚鎷瘋礉鍒發ib鐩綍涓嬨?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">浣犱篃鍙互鏍規嵁闇瑕侀夋嫨鎵闇鐨勯」鐩繘琛岀紪璇戯紝鍏朵腑欏圭洰cppunit涓洪潤鎬佸簱錛宑ppunit_dll涓哄姩鎬佸簱錛岀敓鎴愮殑搴撴枃浠朵負錛?/p><pre style="word-wrap: break-word; white-space: normal; line-height: 26px; text-align: left; background-color: #f5f5f5; color: green; ">cppunit.lib錛?闈欐佸簱release鐗?cppunitd.lib錛?闈欐佸簱debug鐗?cppunit_dll.lib錛?鍔ㄦ佸簱release鐗?cppunitd_dll.lib錛氬姩鎬佸簱debug鐗?/pre><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">瑕佷嬌鐢–ppUnit錛岃繕寰楄緗ソ澶存枃浠跺拰搴撴枃浠惰礬寰勶紝浠C6涓轟緥錛岄夋嫨Tools/Options/Directories錛屽湪Include files鍜孡ibrary files涓垎鍒坊鍔?CppUnitPath%/include鍜?CppUnitPath%/lib錛屽叾涓?CppUnitPath%琛ㄧずCppUnit鎵鍦ㄨ礬寰勩?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鍋氬ソ鍑嗗宸ヤ綔鍚庯紝鎴戜滑灝卞彲浠ョ紪鍐欒嚜宸辯殑鍗曞厓嫻嬭瘯浠g爜浜嗐傞渶璇存槑鐨勬槸錛孋ppUnit鎵鐢ㄧ殑鍔ㄦ佽繍琛屾湡搴撳潎涓哄綰跨▼鍔ㄦ佸簱錛屽洜姝や綘鐨勫崟鍏冩祴璇曠▼搴忎篃寰椾嬌鐢ㄧ浉搴旇緗紝鍚﹀垯浼氬彂鐢熷啿紿併?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">姒傚康</p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鍦ㄤ嬌鐢ㄤ箣鍓嶏紝鎴戜滑鏈夊繀瑕佽璇嗕竴涓婥ppUnit涓殑涓昏綾伙紝褰撶劧浣犱篃鍙互鍏堢湅鍚庨潰鐨勪緥瀛愶紝閬囧埌闂鍐嶅洖榪囧ご鏉ョ湅榪欎竴鑺傘?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">CppUnit鏍稿績鍐呭涓昏鍖呮嫭鍏釜鏂歸潰錛?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">1. 嫻嬭瘯瀵硅薄錛圱est錛孴estFixture錛?..錛夛細鐢ㄤ簬寮鍙戞祴璇曠敤渚嬶紝浠ュ強瀵規祴璇曠敤渚嬭繘琛岀粍緇囩鐞嗐?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">2. 嫻嬭瘯緇撴灉錛圱estResult錛夛細澶勭悊嫻嬭瘯鐢ㄤ緥鎵ц緇撴灉銆俆estResult涓庝笅闈㈢殑TestListener閲囩敤鐨勬槸瑙傚療鑰呮ā寮忥紙Observer Pattern錛夈?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">3. 嫻嬭瘯緇撴灉鐩戝惉鑰咃紙TestListener錛夛細TestListener浣滀負TestResult鐨勮瀵熻咃紝鎷呬換瀹為檯鐨勭粨鏋滃鐞嗚鑹層?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">4. 緇撴灉杈撳嚭錛圤utputter錛夛細灝嗙粨鏋滆繘琛岃緭鍑猴紝鍙互鍒跺畾涓嶅悓鐨勮緭鍑烘牸寮忋?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">5. 瀵硅薄宸ュ巶錛圱estFactory錛夛細鐢ㄤ簬鍒涘緩嫻嬭瘯瀵硅薄錛屽嫻嬭瘯鐢ㄤ緥榪涜鑷姩鍖栫鐞嗐?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">6. 嫻嬭瘯鎵ц浣擄紙TestRunner錛夛細鐢ㄤ簬榪愯涓涓祴璇曘?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">浠ヤ笂鍚勬ā鍧楃殑涓昏綾葷戶鎵跨粨鏋勫涓嬶細</p><pre style="word-wrap: break-word; white-space: normal; line-height: 26px; text-align: left; background-color: #f5f5f5; color: green; ">Test TestFixture TestResult TestListener _______|_________ | | | | | TestSuccessListener TestComposite TestLeaf | | | |____________| TestResultCollector TestSuit | TestCase | TestCaller<Fixture> Outputter TestFactory TestRunner ____________________|_________________ | | | | TestFactoryRegistry CompilerOutputter TextOutputter XmlOutputter | TestSuiteFactory<TestCaseType></pre><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鎺ヤ笅鏉ュ啀瀵瑰叾涓竴浜涘叧閿被浣滀互浠嬬粛銆?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">Test錛氭墍鏈夋祴璇曞璞$殑鍩虹被銆?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">CppUnit閲囩敤鏍戝艦緇撴瀯鏉ョ粍緇囩鐞嗘祴璇曞璞★紙綾諱技浜庣洰褰曟爲錛夛紝鍥犳榪欓噷閲囩敤浜嗙粍鍚堣璁℃ā寮忥紙Composite Pattern錛夛紝Test鐨勪袱涓洿鎺ュ瓙綾籘estLeaf鍜孴estComposite鍒嗗埆琛ㄧず“嫻嬭瘯鏍?#8221;涓殑鍙惰妭鐐瑰拰闈炲彾鑺傜偣錛屽叾涓璗estComposite涓昏璧風粍緇囩鐞嗙殑浣滅敤錛屽氨鍍忕洰褰曟爲涓殑鏂囦歡澶癸紝鑰孴estLeaf鎵嶆槸鏈緇堝叿鏈夋墽琛岃兘鍔涚殑嫻嬭瘯瀵硅薄錛屽氨鍍忕洰褰曟爲涓殑鏂囦歡銆?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">Test鏈閲嶈鐨勪竴涓叕鍏辨帴鍙d負錛?/p><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">virtual void run(TestResult *result) = 0;</div><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鍏朵綔鐢ㄤ負鎵ц嫻嬭瘯瀵硅薄錛屽皢緇撴灉鎻愪氦緇檙esult銆?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鍦ㄥ疄闄呭簲鐢ㄤ腑錛屾垜浠竴鑸笉浼氱洿鎺ヤ嬌鐢═est銆乀estComposite浠ュ強TestLeaf錛岄櫎闈炴垜浠閲嶆柊瀹氬埗鏌愪簺鏈哄埗銆?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestFixture錛氱敤浜庣淮鎶や竴緇勬祴璇曠敤渚嬬殑涓婁笅鏂囩幆澧冦?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鍦ㄥ疄闄呭簲鐢ㄤ腑錛屾垜浠粡甯鎬細寮鍙戜竴緇勬祴璇曠敤渚嬫潵瀵規煇涓被鐨勬帴鍙e姞浠ユ祴璇曪紝鑰岃繖浜涙祴璇曠敤渚嬪緢鍙兘鍏鋒湁鐩稿悓鐨勫垵濮嬪寲鍜屾竻鐞嗕唬鐮併備負姝わ紝CppUnit寮曞叆TestFixture鏉ュ疄鐜拌繖涓鏈哄埗銆?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestFixture鍏鋒湁浠ヤ笅涓や釜鎺ュ彛錛屽垎鍒敤浜庡鐞嗘祴璇曠幆澧冪殑鍒濆鍖栦笌娓呯悊宸ヤ綔錛?/p><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">virtual void setUp(); <br />virtual void tearDown(); </div><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestCase錛氭祴璇曠敤渚嬶紝浠庡悕瀛椾笂灝卞彲浠ョ湅鍑烘潵錛屽畠渚挎槸鍗曞厓嫻嬭瘯鐨勬墽琛屽璞°?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestCase浠嶵est鍜孴estFixture澶氱戶鎵胯屾潵錛岄氳繃鎶奣est::run鍒跺畾鎴愭ā鏉垮嚱鏁幫紙Template Method錛夎屽皢涓や釜鐖剁被鐨勬搷浣滆瀺鍚堝湪涓璧鳳紝run鍑芥暟鐨勪吉瀹氫箟濡備笅錛?/p><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">// 浼唬鐮?nbsp;<br />void TestCase::run(TestResult* result)<br />{<br />    result->startTest(this); // 閫氱煡result嫻嬭瘯寮濮?br />    if( result->protect(this, &TestCase::setUp) ) // 璋冪敤setUp錛屽垵濮嬪寲鐜<br />        result->protect(this, &TestCase::runTest); // 鎵цrunTest錛屽嵆鐪熸鐨勬祴璇曚唬鐮?br />    result->protect(this, &TestCase::tearDown); // 璋冪敤tearDown錛屾竻鐞嗙幆澧?br />    result->endTest(this); // 閫氱煡result嫻嬭瘯緇撴潫<br />}</div><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">榪欓噷瑕佹彁鍒扮殑鏄嚱鏁皉unTest錛屽畠鏄疶estCase瀹氫箟鐨勪竴涓帴鍙o紝鍘熷瀷濡備笅錛?/p><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">virtual void runTest();</div><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鐢ㄦ埛闇浠嶵estCase媧劇敓鍑哄瓙綾誨茍瀹炵幇runTest浠ュ紑鍙戣嚜宸辨墍闇鐨勬祴璇曠敤渚嬨?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鍙﹀榪樿鎻愬埌鐨勫氨鏄疶estResult鐨刾rotect鏂規硶錛屽叾浣滅敤鏄鎵ц鍑芥暟錛堝疄闄呬笂鏄嚱鏁板璞★級鐨勯敊璇俊鎭紙鍖呮嫭鏂█鍜屽紓甯哥瓑錛夎繘琛屾崟鑾鳳紝浠庤屽疄鐜板嫻嬭瘯緇撴灉鐨勭粺璁°?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestSuit錛氭祴璇曞寘錛屾寜鐓ф爲褰㈢粨鏋勭鐞嗘祴璇曠敤渚?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestSuit鏄疶estComposite鐨勪竴涓疄鐜幫紝瀹冮噰鐢╲ector鏉ョ鐞嗗瓙嫻嬭瘯瀵硅薄錛圱est錛夛紝浠庤屽艦鎴愰掑綊鐨勬爲褰㈢粨鏋勩?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestCaller錛歍estCase閫傞厤鍣紙Adapter錛夛紝瀹冨皢鎴愬憳鍑芥暟杞崲鎴愭祴璇曠敤渚?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">铏界劧鎴戜滑鍙互浠嶵estCase媧劇敓鑷繁鐨勬祴璇曠被錛屼絾浠嶵estCase綾葷殑瀹氫箟鍙互鐪嬪嚭錛屽畠鍙兘鏀寔涓涓祴璇曠敤渚嬶紝榪欏浜庢祴璇曚唬鐮佺殑緇勭粐鍜岀淮鎶ゅ緢涓嶆柟渚匡紝灝ゅ叾鏄偅浜涙湁鍏卞悓涓婁笅鏂囩幆澧冪殑涓緇勬祴璇曘備負姝わ紝CppUnit鎻愪緵浜員estCaller浠ヨВ鍐寵繖涓棶棰樸?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestCaller鏄竴涓ā鏉跨被錛屽畠浠ュ疄鐜頒簡TestFixture鎺ュ彛鐨勭被涓烘ā鏉垮弬鏁幫紝灝嗙洰鏍囩被涓煇涓鍚坮unTest鍘熷瀷鐨勬祴璇曟柟娉曢傞厤鎴怲estCase鐨勫瓙綾匯?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鍦ㄥ疄闄呭簲鐢ㄤ腑錛屾垜浠ぇ澶氶噰鐢═estFixture鍜孴estCaller鐩哥粍鍚堢殑鏂瑰紡錛屽叿浣撲緥瀛愬弬瑙佸悗鏂囥?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestResult鍜孴estListener錛氬鐞嗘祴璇曚俊鎭拰緇撴灉</p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鍓嶉潰宸茬粡鎻愬埌錛孴estResult鍜孴estListener閲囩敤浜嗚瀵熻呮ā寮忥紝TestResult緇存姢涓涓敞鍐岃〃錛岀敤浜庣鐞嗗悜鍏剁櫥璁拌繃鐨凾estListener錛屽綋TestResult鏀跺埌嫻嬭瘯瀵硅薄錛圱est錛夌殑嫻嬭瘯淇℃伅鏃訛紝鍐嶄竴涓鍒嗗彂緇欏畠鎵綆¤緰鐨凾estListener銆傝繖涓璁捐鏈夊姪浜庡疄鐜板鍚屼竴嫻嬭瘯鐨勫縐嶅鐞嗘柟寮忋?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestFactory錛氭祴璇曞伐鍘?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">榪欐槸涓涓緟鍔╃被錛岄氳繃鍊熷姪涓緋誨垪瀹忓畾涔夎嫻嬭瘯鐢ㄤ緥鐨勭粍緇囩鐞嗗彉寰楄嚜鍔ㄥ寲銆傚弬瑙佸悗闈㈢殑渚嬪瓙銆?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestRunner錛氱敤浜庢墽琛屾祴璇曠敤渚?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">TestRunner灝嗗緟鎵ц鐨勬祴璇曞璞$鐞嗚搗鏉ワ紝鐒跺悗渚涚敤鎴瘋皟鐢ㄣ傚叾鎺ュ彛涓猴細</p><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">virtual void addTest( Test *test ); virtual void run( TestResult &controller, const std::string &testPath = "" );</div><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">榪欎篃鏄竴涓緟鍔╃被錛岄渶娉ㄦ剰鐨勬槸錛岄氳繃addTest娣誨姞鍒癟estRunner涓殑嫻嬭瘯瀵硅薄蹇呴』鏄氳繃new鍔ㄦ佸垱寤虹殑錛岀敤鎴蜂笉鑳藉垹闄よ繖涓璞★紝鍥犱負TestRunner灝嗚嚜琛岀鐞嗘祴璇曞璞$殑鐢熷懡鏈熴?/p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">浣跨敤</p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鍏堣鎴戜滑鐪嬬湅涓涓畝鍗曠殑渚嬪瓙錛?/p><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">#include <cppunit/TestCase.h><br />#include <cppunit/TestResult.h><br />#include <cppunit/TestResultCollector.h><br />#include <cppunit/TextOutputter.h><br /><br />// 瀹氫箟嫻嬭瘯鐢ㄤ緥<br />class SimpleTest : public CppUnit::TestCase<br />{<br />public:<br />    void runTest() // 閲嶈澆嫻嬭瘯鏂規硶<br />    {<br />        int i = 1;<br />        CPPUNIT_ASSERT_EQUAL(0, i);<br />    }<br />};<br /><br />int main(int argc, char* argv[])<br />{<br />    CppUnit::TestResult r; <br />    CppUnit::TestResultCollector rc;<br />    r.addListener(&rc); // 鍑嗗濂界粨鏋滄敹闆嗗櫒 <br /><br />    SimpleTest t;<br />    t.run(&r); // 榪愯嫻嬭瘯鐢ㄤ緥<br /><br />    CppUnit::TextOutputter o(&rc, std::cout);<br />    o.write(); // 灝嗙粨鏋滆緭鍑?br /><br />    return 0;<br />}</div><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">緙栬瘧鍚庤繍琛岋紝杈撳嚭緇撴灉涓猴細</span><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">!!!FAILURES!!!<br />Test Results:<br />Run: 1 Failures: 1 Errors: 0<br /><br />1) test: (F) line: 18 E:/CppUnitExamples/SimpleTest.cpp<br />equality assertion failed<br />- Expected: 1<br />- Actual : 0</div><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">涓婇潰鐨勪緥瀛愬緢綆鍗曪紝闇璇存槑鐨勬槸CPPUNIT_ASSERT_EQUAL瀹忋侰ppUnit瀹氫箟浜嗕竴緇勫畯鐢ㄤ簬媯嫻嬮敊璇紝CPPUNIT_ASSERT_EQUAL鏄叾涓箣涓錛屽綋鏂█澶辮觸鏃訛紝CppUnit渚夸細灝嗛敊璇俊鎭姤鍛婄粰TestResult銆傝繖浜涘畯瀹氫箟鐨勮鏄庡涓嬶細</p><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; "><p>CPPUNIT_ASSERT(condition)錛氬垽鏂璫ondition鐨勫兼槸鍚︿負鐪燂紝濡傛灉涓哄亣鍒欑敓鎴愰敊璇俊鎭?/p><p>CPPUNIT_ASSERT_MESSAGE(message, condition)錛氫笌CPPUNIT_ASSERT綾諱技錛屼絾緇撴灉涓哄亣鏃舵姤鍛妋esssage淇℃伅銆?/p><p>CPPUNIT_FAIL(message)錛氱洿鎺ユ姤鍛妋esssage閿欒淇℃伅銆?/p><p>CPPUNIT_ASSERT_EQUAL(expected, actual)錛氬垽鏂璭xpected鍜宎ctual鐨勫兼槸鍚︾浉絳夛紝濡傛灉涓嶇瓑杈撳嚭閿欒淇℃伅銆?/p><p>CPPUNIT_ASSERT_EQUAL_MESSAGE(message, expected, actual)錛氫笌CPPUNIT_ASSERT_EQUAL綾諱技錛屼絾鏂█澶辮觸鏃惰緭鍑簃essage淇℃伅銆?/p><p>CPPUNIT_ASSERT_DOUBLES_EQUAL(expected, actual, delta)錛氬垽鏂璭xpected涓巃ctual鐨勫亸宸槸鍚﹀皬浜巇elta錛岀敤浜庢誕鐐規暟姣旇緝銆?/p><p>CPPUNIT_ASSERT_THROW(expression, ExceptionType)錛氬垽鏂墽琛岃〃杈懼紡expression鍚庢槸鍚︽姏鍑篍xceptionType寮傚父銆?/p><p>CPPUNIT_ASSERT_NO_THROW(expression)錛氭柇璦鎵ц琛ㄨ揪寮廵xpression鍚庢棤寮傚父鎶涘嚭銆?/p></div><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">鎺ヤ笅鏉ュ啀鐪嬬湅TestFixture鍜孴estCaller鐨勭粍鍚堜嬌鐢細</p><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">#include <cppunit/TestCase.h><br />#include <cppunit/TestResult.h><br />#include <cppunit/TestResultCollector.h><br />#include <cppunit/TextOutputter.h><br />#include <cppunit/TestCaller.h><br />#include <cppunit/TestRunner.h><br /><br />// 瀹氫箟嫻嬭瘯綾?br />class StringTest : public CppUnit::TestFixture<br />{<br />public:<br />    void setUp() // 鍒濆鍖?br />    {<br />        m_str1 = "Hello, world";<br />        m_str2 = "Hi, cppunit";<br />    }<br /><br />    void tearDown() // 娓呯悊<br />    {<br />    }<br /><br />    void testSwap() // 嫻嬭瘯鏂規硶1<br />    {<br />        std::string str1 = m_str1;<br />        std::string str2 = m_str2;<br />        m_str1.swap(m_str2);<br />        <br />        CPPUNIT_ASSERT(m_str1 == str2);<br />        CPPUNIT_ASSERT(m_str2 == str1);<br />    }<br /><br />    void testFind() // 嫻嬭瘯鏂規硶2<br />    {<br />        int pos1 = m_str1.find(',');<br />        int pos2 = m_str2.rfind(',');<br /><br />        CPPUNIT_ASSERT_EQUAL(5, pos1);<br />        CPPUNIT_ASSERT_EQUAL(2, pos2);<br />    }<br /><br />protected:<br />    std::string     m_str1;<br />    std::string     m_str2;<br />};<br /><br />int main(int argc, char* argv[])<br />{<br />    CppUnit::TestResult r; <br />    CppUnit::TestResultCollector rc;<br />    r.addListener(&rc); // 鍑嗗濂界粨鏋滄敹闆嗗櫒 <br /><br />    CppUnit::TestRunner runner; // 瀹氫箟鎵ц瀹炰綋<br />    runner.addTest(new CppUnit::TestCaller<StringTest>("testSwap", &StringTest::testSwap)); // 鏋勫緩嫻嬭瘯鐢ㄤ緥1<br />    runner.addTest(new CppUnit::TestCaller<StringTest>("testFind", &StringTest::testFind)); // 鏋勫緩嫻嬭瘯鐢ㄤ緥2<br />    runner.run(r); // 榪愯嫻嬭瘯<br /><br />    CppUnit::TextOutputter o(&rc, std::cout);<br />    o.write(); // 灝嗙粨鏋滆緭鍑?br /><br />    return rc.wasSuccessful() ? 0 : -1;<br />}</div><span style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">緙栬瘧鍚庤繍琛岀粨鏋滀負錛?/span><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">OK (2 tests)</div><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">涓婇潰鐨勪唬鐮佷粠鍔熻兘涓婅娌℃湁浠涔堥棶棰橈紝浣嗙紪鍐欒搗鏉ュお綣佺悙浜嗭紝涓烘錛屾垜浠彲浠ュ熷姪CppUnit瀹氫箟鐨勪竴濂楄緟鍔╁畯錛屽皢嫻嬭瘯鐢ㄤ緥鐨勫畾涔夊拰娉ㄥ唽鍙樺緱鑷姩鍖栥備笂闈㈢殑浠g爜鏀歸犲悗濡備笅錛?/p><div style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">#include <cppunit/TestResult.h><br />#include <cppunit/TestResultCollector.h><br />#include <cppunit/TextOutputter.h><br />#include <cppunit/TestRunner.h><br />#include <cppunit/extensions/HelperMacros.h><br /><br /><br />// 瀹氫箟嫻嬭瘯綾?br />class StringTest : public CppUnit::TestFixture<br />{<br />    CPPUNIT_TEST_SUITE(StringTest);  // 瀹氫箟嫻嬭瘯鍖?br />    CPPUNIT_TEST(testSwap);  // 娣誨姞嫻嬭瘯鐢ㄤ緥1<br />    CPPUNIT_TEST(testFind);  // 娣誨姞嫻嬭瘯鐢ㄤ緥2<br />    CPPUNIT_TEST_SUITE_END();  // 緇撴潫嫻嬭瘯鍖呭畾涔?br />    <br />public:<br />    void setUp() // 鍒濆鍖?br />    {<br />        m_str1 = "Hello, world";<br />        m_str2 = "Hi, cppunit";<br />    }<br /><br />    void tearDown() // 娓呯悊<br />    {<br />    }<br /><br />    void testSwap() // 嫻嬭瘯鏂規硶1<br />    {<br />        std::string str1 = m_str1;<br />        std::string str2 = m_str2;<br />        m_str1.swap(m_str2);<br />        <br />        CPPUNIT_ASSERT(m_str1 == str2);<br />        CPPUNIT_ASSERT(m_str2 == str1);<br />    }<br /><br />    void testFind() // 嫻嬭瘯鏂規硶2<br />    {<br />        int pos1 = m_str1.find(',');<br />        int pos2 = m_str2.rfind(',');<br /><br />        CPPUNIT_ASSERT_EQUAL(5, pos1);<br />        CPPUNIT_ASSERT_EQUAL(2, pos2);<br />    }<br /><br />protected:<br />    std::string     m_str1;<br />    std::string     m_str2;<br />};<br /><br />CPPUNIT_TEST_SUITE_REGISTRATION(StringTest); // 鑷姩娉ㄥ唽嫻嬭瘯鍖?br /><br />int main(int argc, char* argv[])<br />{<br />    CppUnit::TestResult r; <br />    CppUnit::TestResultCollector rc;<br />    r.addListener(&rc); // 鍑嗗濂界粨鏋滄敹闆嗗櫒 <br /><br />    CppUnit::TestRunner runner; // 瀹氫箟鎵ц瀹炰綋<br />    runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());<br />    runner.run(r); // 榪愯嫻嬭瘯<br /><br />    CppUnit::TextOutputter o(&rc, std::cout);<br />    o.write(); // 灝嗙粨鏋滆緭鍑?br /><br />    return rc.wasSuccessful() ? 0 : -1;<br />}</div><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">CppUnit鐨勭畝鍗曚粙緇嶅氨鍒版錛岀浉淇′綘宸茬粡浜嗚В浜嗗叾涓殑鍩烘湰姒傚康錛屼篃鑳藉寮鍙戝崟鍏冩祴璇曚唬鐮佷簡銆?br /><br />杞嚜錛?a >http://blog.csdn.net/freefalcon/article/details/753819</a></p><img src ="http://www.shnenglu.com/tankzhouqiang/aggbug/166911.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/tankzhouqiang/" target="_blank">鍛ㄥ己</a> 2012-03-01 20:25 <a href="http://www.shnenglu.com/tankzhouqiang/archive/2012/03/01/166911.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p> <a href="http://www.shnenglu.com/" title="精品视频久久久久">精品视频久久久久</a> <div class="friend-links"> </div> </div> </footer> <a href="http://www.szebase.com.cn" target="_blank">99久久99久久精品免费看蜜桃</a>| <a href="http://www.yingyu3g.cn" target="_blank">久久久久无码精品国产app</a>| <a href="http://www.daocheyingxiang.cn" target="_blank">国产精品热久久无码av</a>| <a href="http://www.animin.cn" target="_blank">久久99久久成人免费播放</a>| <a href="http://www.zyhyhz.cn" target="_blank">久久这里只有精品首页</a>| <a href="http://www.s360.com.cn" target="_blank">国内精品人妻无码久久久影院 </a>| <a href="http://www.918gn.cn" target="_blank">国产成人99久久亚洲综合精品</a>| <a href="http://www.ehzc.cn" target="_blank">94久久国产乱子伦精品免费</a>| <a href="http://www.02324.cn" target="_blank">中文字幕久久久久人妻</a>| <a href="http://www.wbcyn.cn" target="_blank">国产精品99精品久久免费</a>| <a href="http://www.fanwenku.com.cn" target="_blank">日本久久久久久中文字幕</a>| <a href="http://www.hellorolex.cn" target="_blank">狠狠88综合久久久久综合网 </a>| <a href="http://www.jsfair.cn" target="_blank">久久精品aⅴ无码中文字字幕不卡</a>| <a href="http://www.zhaopf.com.cn" target="_blank">久久99精品久久久久久齐齐</a>| <a href="http://www.wuxicld.cn" target="_blank">成人综合久久精品色婷婷</a>| <a href="http://www.ciao-surveys.cn" target="_blank">国产精品久久久亚洲</a>| <a href="http://www.qdjybj.cn" target="_blank">亚洲精品成人网久久久久久</a>| <a href="http://www.rcjmwj.com.cn" target="_blank">精品人妻伦九区久久AAA片69</a>| <a href="http://www.p8595.cn" target="_blank">欧美激情一区二区久久久</a>| <a href="http://www.xahjqc.cn" target="_blank">91超碰碰碰碰久久久久久综合</a>| <a href="http://www.henpu.cn" target="_blank">亚洲伊人久久精品影院</a>| <a href="http://www.interagency.cn" target="_blank">狠狠综合久久综合中文88</a>| <a href="http://www.webidea.com.cn" target="_blank">久久久噜噜噜www成人网</a>| <a href="http://www.yhlj.net.cn" target="_blank">国产精品久久新婚兰兰</a>| <a href="http://www.jijijian.cn" target="_blank">成人a毛片久久免费播放</a>| <a href="http://www.gjqa.cn" target="_blank">A狠狠久久蜜臀婷色中文网</a>| <a href="http://www.cyjeans.com.cn" target="_blank">影音先锋女人AV鲁色资源网久久</a>| <a href="http://www.520jj.cn" target="_blank">久久本道综合久久伊人</a>| <a href="http://www.vcdordvd.cn" target="_blank">伊人久久大香线焦综合四虎</a>| <a href="http://www.xnhtml.com.cn" target="_blank">国产精品一区二区久久不卡</a>| <a href="http://www.aidelu.cn" target="_blank">午夜久久久久久禁播电影</a>| <a href="http://www.662z.cn" target="_blank">久久人人爽人人爽人人AV </a>| <a href="http://www.17youshi.cn" target="_blank">久久综合给合久久狠狠狠97色 </a>| <a href="http://www.fbnnfzx.cn" target="_blank">国产精品美女久久久久</a>| <a href="http://www.jxfic.org.cn" target="_blank">国产偷久久久精品专区</a>| <a href="http://www.aa110.cn" target="_blank">亚洲日本久久久午夜精品</a>| <a href="http://www.botouvr.cn" target="_blank">久久久久亚洲AV无码观看</a>| <a href="http://www.4527.com.cn" target="_blank">无码人妻精品一区二区三区久久久</a>| <a href="http://www.hhhkk.cn" target="_blank">久久久久国产一区二区三区</a>| <a href="http://www.i231.cn" target="_blank">精品久久国产一区二区三区香蕉</a>| <a href="http://www.dxclub.com.cn" target="_blank">久久免费精品一区二区</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>