已存在一个win32项目(MoneyImplement),不能生成dll文件。现在要对MoneyImplement里面的CMoney类进行测试。我新建了一个项目CppUnitDemo
文件夹列表如下:
\MoneyImplement
\MoneyImplement\CppUnitDemo
在CppUnitDemo中include "..\Money.h "
编译的时候出现link 错误
MoneyTest.obj : error LNK2019: unresolved external symbol "public: class std::basic_string <char,struct std::char_traits <char> ,class std::allocator <char> > __thiscall CMoney::getCurrency(void)const " (?getCurrency@CMoney@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function "public: void __thiscall MoneyTest::testConstructor(void) " (?testConstructor@MoneyTest@@QAEXXZ)
MoneyTest.obj : error LNK2019: unresolved external symbol "public: double __thiscall CMoney::getAmount(void)const " (?getAmount@CMoney@@QBENXZ) referenced in function "public: void __thiscall MoneyTest::testConstructor(void) " (?testConstructor@MoneyTest@@QAEXXZ)
好像是找不到CMoney类中的方法。
是不是MoneyImplement项目必须是MFC Extension Dll的Project?但是如果对已存在的项目添加测试,原来的项目不能作任何改变,该如何?
------解决方案--------------------------------------------------------
把CMoney的cpp文件也加到你的单元测试工程。通常我把所有的cpp文件都加到unit test project,当然对于theApp要特殊处理一下