51Testing软件测试论坛

标题: 求教cppunit的问题 [打印本页]

作者: dyjyhx    时间: 2006-2-12 10:51
标题: 求教cppunit的问题
我用的是cppunit 1.10.2版本

#include "C:\\Program Files\\cppunit-1.10.2\\include\\cppunit\\extensions\\TestFactoryRegistry.h"
#include "C:\\Program Files\\cppunit-1.10.2\\include\\cppunit\\ui\\mfc\\TestRunner.h"
int main()
{
        //CppUnit::TextUi::TestRunner runner;
        CppUnit::MfcUi::TestRunner runner;
        CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry("alltest");

        runner.addTest(registry.makeTest());
        runner.run();
       
        return 0;
}
编译后出现

c:\program files\cppunit-1.10.2\include\cppunit\ui\mfc\mfctestrunner.h(53) : error C2079: 'MfcTestRunner' uses undefined class 'AFX_EXT_CLASS'
c:\program files\cppunit-1.10.2\include\cppunit\ui\mfc\mfctestrunner.h(53) : error C2239: unexpected token '{' following declaration of 'MfcTestRunner'
c:\\program files\\cppunit-1.10.2\\include\\cppunit\\ui\\mfc\\testrunner.h(14) : error C2146: syntax error : missing ';' before identifier 'TestRunner'
c:\\program files\\cppunit-1.10.2\\include\\cppunit\\ui\\mfc\\testrunner.h(14) : error C2370: 'MfcTestRunner' : redefinition; different storage class
        c:\program files\cppunit-1.10.2\include\cppunit\ui\mfc\mfctestrunner.h(53) : see declaration of 'MfcTestRunner'
c:\\program files\\cppunit-1.10.2\\include\\cppunit\\ui\\mfc\\testrunner.h(14) : error C2888: 'int CppUnit::MfcTestRunner' : symbol cannot be defined within namespace 'MfcUi'
c:\\program files\\cppunit-1.10.2\\include\\cppunit\\ui\\mfc\\testrunner.h(14) : fatal error C1004: unexpected end of file found
Error executing cl.exe.


使用#include "C:\\Program Files\\cppunit-1.10.2\\include\\cppunit\\ui\\mfc\\TestRunner.h"就没有问题。
是什么原因?请高手指点一下,先谢了
作者: zixuxuwu    时间: 2006-2-13 22:16
如果搞不清楚的话,建议按照cppUni自带的例子的设置来设置。
作者: dyjyhx    时间: 2006-2-14 11:35
看了各位大虾的质料,个人认为可能是以下原因:
   使用mfc\\TestRunner.h,则只能在InitInstance()函数中添加
        CppUnit::MfcUi::TestRunner runner;
        CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry("alltest");

        runner.addTest(registry.makeTest());
        runner.run();
这是Mfc工程。运行后为mfc界面方法

建立console工程,只能使用Text\\TestRunner.h
在main 函数中添加
CppUnit::TextUi::TestRunner runner;
        CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry("alltest");

        runner.addTest(registry.makeTest());
        runner.run();
运行后console方法。

不知道是不是这个原因?




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