51Testing软件测试论坛

标题: cppunit 框架测试问题点 [打印本页]

作者: royz    时间: 2012-5-11 15:50
标题: cppunit 框架测试问题点
在win 32 控制台测试出现如下问题请问怎么回事?请各位帮忙解决.

1、新建Win32 Console Application工程,命名为“dd”(可取其它名字),并指定存储路径;

2、在测试项目中设置(非常重要)

① 在VC中,在菜单中,选择Project Settings'C/C++'Category列表中选择'C++ Language’, 选择'enable Run-Time Type Information (RTTI)'。
② 在VC中,在菜单中,选择Project Settings'C/C++'Category列表中选择'Code generation',在Use run-time library列表中,对于Debug版,选择'Debug Multithreaded DLL',对于release版,选择'Multithreaded DLL';
③ 在VC中,在菜单中,选择Project Settings'Link',在'Object/library modules'中添入需要的lib文件:cppunitX.lib (debug模式为cppunitd.lib, release 模式为cppunit.lib )、testrunnerX.lib(debug模式为testrunnerd.lib, release 模式为testrunner.lib,debug Unicode模式为testrunnerud.lib, release Unicode模式为testrunneru.lib)

3、新建测试类“MathTest”


4、修改文件“MathTest.h”

#include <cppunit/extensions/HelperMacros.h>

class mathtest : public CppUnit::TestFixture
{
        public:
                mathtest();
                virtual ~mathtest();
        protected:
         int m_value1,m_value2;

        public:
                 
                // 初始化函数
                void setUp ();
                // 清理函数
                void tearDown();         
                // 添加测试函数
                void testFoundInArray();
                        void testAdd();
                        void testMinus();
                // 可以添加新的测试函数
};


5、修改文件“MathTest.cpp”
void mathtest::setUp()
{
        m_value1=1;
        m_value2=2;

}
void mathtest::tearDown()
{
}
void mathtest::testAdd()
{
        int result=m_value1+value2;
        CPPUNIT_ASSERT( result==3);
}
void mathtest::testMinus()
{
        int result=m_value1-value2;
        CPPUNIT_ASSERT( result==-1);
}


6、修改main函数
// cppunit.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <mathtest.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>

int main(int argc, char* argv[])
{
        CppUnit::TextUi::TestRunner runner;         

           // 从注册的TestSuite中获取特定的TestSuite, 没有参数获取未命名的TestSuite.
        CppUnit::TestSuite *suite=new CppUnit::TestSuite();
        suite->addTest(new CppUnit::TestCaller<mathtest ("testAdd",&mathtest::testAdd));

        suite->addTest(new CppUnit::TestCaller<mathtest ("testMinus",&mathtest::testMinus));



        runner.addTest(suite);
        // 运行测试
        runner.run("",true);
       
        return 0;
}


7、编译,若编译出错,出现如下错误,请帮忙

: fatal error C1083: Cannot open include file: 'cppunit/extensions/HelperMacros.h': No such file or directory




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2