最阳春的CPPUNIT单元测试所要操作的部分有4个(也许说3个更确切?因为testrunner有且只有一个)
CppUnit::MfcUi::TestRunner GUI介面的testrunner
CppUnit::TextUi::TestRunner 字符串介面的testrunner
CppUnit::TestFactoryRegistry::getRegistry() 测试节点的工厂,所有用宏加入的节点都是加在这个工厂里的啦...
CppUnit::TestFixture 测试用例,也是一个节点
//TestFixture基本用法
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
//把该测试用例加入到CPPUNIT 根测试里去
CPPUNIT_TEST_SUITE_REGISTRATION
CPPUNIT_TEST_SUITE_REGISTRATION( TestResultCollectorTest );
CPPUNIT_NS::TestFixture //从它继承
virtual void TestFixture::setUp();
virtual void TestFixture::tearDown();
CPPUNIT_TEST_SUITE //定义一个suite
CPPUNIT_TEST //定义一个测试用例
CPPUNIT_TEST_EXCEPTION //有异常的测试用例
CPPUNIT_TEST_SUITE_END
//MFC GUI启动单元测试
#include <cppunit/ui/mfc/TestRunner.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
CPPUNIT_NS::MfcUi::TestRunner runner;
runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
runner.run();
//控制台启动单元测试
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() );
runner.run( "", false );
//测试用例与节点之间的连接
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TestResultCollectorTest, coreSuiteName() );
//节点与根结点之间的连接
CPPUNIT_REGISTRY_ADD_TO_DEFAULT(coreSuiteName());
//节点与节点之间的连接.
CPPUNIT_REGISTRY_ADD
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( coreSuiteName(), "father" );
posted on 2008-12-02 16:04
鹿哥 阅读(608)
评论(0) 编辑 收藏 引用 所属分类:
CppUnit