我有一个老旧的C++应用程序,现在我正在尝试为它编写一些单元测试。我已经在解决方案中创建了第二个项目,该项目构建为一个单元测试可执行文件(使用googletest)。该测试项目引用主项目的头文件。当我尝试使用主项目中的某个类时,测试项目可以正常构建,直到这个时候。
#include "stdafx.h"
#include "JsContext.h"
#include "gtest/gtest.h"
TEST(JsContextTests, CreateJsContext) {
JsContext context; // linking fails as soon as this line is added
}
Produces..
Error 1 error LNK2001: unresolved external symbol "public: __thiscall JsContext::JsContext(void)" (??0JsContext@@QAE@XZ) JsContextTests.obj tests
Error 2 fatal error LNK1120: 1 unresolved externals D:\Projects\Js-Clean\src\Debug\tests.exe tests
主要的可执行文件没有生成.lib文件,所以我不确定测试项目应该链接什么。
如何最好地对另一个EXE项目中的类进行单元测试?