CppUnit VS2008下使用(1)

来源:互联网 发布:淘宝商品资质上传技巧 编辑:程序博客网 时间:2024/05/18 23:25
配置好环境之后,首先打开VS2008建立一个win32 控制台应用程序(空项目),不是空项目也可以,只是不习惯VS给自动生成的东西。之后新建一个cpp文件,就叫main.cpp吧。
然后将下面代码复制进去(或敲进去):
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/ui/text/TextTestRunner.h>

class ExampleTestCase : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(ExampleTestCase);
CPPUNIT_TEST(example);
CPPUNIT_TEST_SUITE_END();

protected:
double m_value1;
double m_value2;

public:
void setUp();

protected:
void example();
};

CPPUNIT_TEST_SUITE_REGISTRATION( ExampleTestCase );

void ExampleTestCase::example()
{
CPPUNIT_ASSERT( m_value1 < m_value2 );
}

void ExampleTestCase::setUp()
{
m_value1 = 2.0;
m_value2 = 3.0;
}

void test()
{
CPPUNIT_NS::Test *test = CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
CPPUNIT_NS::TextTestRunner runner;
runner.addTest(test);

runner.run();
}

int main ()
{
test();

char c;
scanf("%c",&c);
return 0;
}

此时编译会出错,因为还没有设置包含文件 库文件等路径。点击上面菜单中“项目->属性”
按下面三个图配置,其中F:\cppunit-1.12.1 为cppunit的路径,要根据实际情况选择的!CppUnit <wbr>VS2008下使用(1)

CppUnit <wbr>VS2008下使用(1)

CppUnit <wbr>VS2008下使用(1)
原创粉丝点击