﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-silekey-文章分类-CppUnit</title><link>http://www.cppblog.com/silekey/category/9022.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 10 Feb 2009 09:55:18 GMT</lastBuildDate><pubDate>Tue, 10 Feb 2009 09:55:18 GMT</pubDate><ttl>60</ttl><item><title>CPPUNIT 使用笔记</title><link>http://www.cppblog.com/silekey/articles/68397.html</link><dc:creator>鹿哥</dc:creator><author>鹿哥</author><pubDate>Tue, 02 Dec 2008 08:04:00 GMT</pubDate><guid>http://www.cppblog.com/silekey/articles/68397.html</guid><wfw:comment>http://www.cppblog.com/silekey/comments/68397.html</wfw:comment><comments>http://www.cppblog.com/silekey/articles/68397.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/silekey/comments/commentRss/68397.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/silekey/services/trackbacks/68397.html</trackback:ping><description><![CDATA[<p>最阳春的CPPUNIT单元测试所要操作的部分有4个(也许说3个更确切?因为testrunner有且只有一个)<br>CppUnit::MfcUi::TestRunner&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GUI介面的testrunner<br>CppUnit::TextUi::TestRunner&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 字符串介面的testrunner<br>CppUnit::TestFactoryRegistry::getRegistry()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 测试节点的工厂,所有用宏加入的节点都是加在这个工厂里的啦...<br>CppUnit::TestFixture&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;测试用例,也是一个节点<br><br>//TestFixture基本用法<br>#include &lt;cppunit/TestFixture.h&gt;<br>#include &lt;cppunit/extensions/HelperMacros.h&gt;</p>
<p>//把该测试用例加入到CPPUNIT 根测试里去<br>CPPUNIT_TEST_SUITE_REGISTRATION<br>CPPUNIT_TEST_SUITE_REGISTRATION( TestResultCollectorTest );</p>
<p>CPPUNIT_NS::TestFixture&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //从它继承<br>virtual void TestFixture::setUp();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>virtual void TestFixture::tearDown();</p>
<p>CPPUNIT_TEST_SUITE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //定义一个suite<br>CPPUNIT_TEST&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //定义一个测试用例<br>CPPUNIT_TEST_EXCEPTION&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //有异常的测试用例<br>CPPUNIT_TEST_SUITE_END</p>
<p><br>//MFC GUI启动单元测试<br>#include &lt;cppunit/ui/mfc/TestRunner.h&gt;<br>#include &lt;cppunit/extensions/TestFactoryRegistry.h&gt;<br>CPPUNIT_NS::MfcUi::TestRunner runner;<br>runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );<br>runner.run();</p>
<p>//控制台启动单元测试<br>#include &lt;cppunit/CompilerOutputter.h&gt;<br>#include &lt;cppunit/extensions/TestFactoryRegistry.h&gt;<br>#include &lt;cppunit/ui/text/TestRunner.h&gt;<br>CppUnit::TextUi::TestRunner runner;<br>CppUnit::TestFactoryRegistry &amp;registry = CppUnit::TestFactoryRegistry::getRegistry();<br>runner.addTest( registry.makeTest() );<br>runner.run( "", false );</p>
<p><br>//测试用例与节点之间的连接<br>CPPUNIT_TEST_SUITE_NAMED_REGISTRATION<br>CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TestResultCollectorTest,&nbsp; coreSuiteName() );</p>
<p>//节点与根结点之间的连接<br>CPPUNIT_REGISTRY_ADD_TO_DEFAULT(coreSuiteName());</p>
<p>//节点与节点之间的连接.<br>CPPUNIT_REGISTRY_ADD<br>CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( coreSuiteName(), "father"&nbsp; );</p>
<img src ="http://www.cppblog.com/silekey/aggbug/68397.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/silekey/" target="_blank">鹿哥</a> 2008-12-02 16:04 <a href="http://www.cppblog.com/silekey/articles/68397.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>