我用一个模拟类创建了一个简单的 C++ 测试项目:
#include <gtest/gtest.h>
#include <gmock/gmock.h>
class TestMock
{
public:
MOCK_CONST_METHOD0(Method1, void());
};
TEST(Test, Test1)
{
TestMock mock;
}
int main(int argc, char * argv[])
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Run Code Online (Sandbox Code Playgroud)
我使用 Visual Studio 2017 (15.3.3)。这是一个带有所有默认设置的 x86 调试项目。
我已将 gtest.lib 和 gmock.lib 添加到链接器。当我编译和链接时,我收到此错误:
1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
1>ConsoleApplication1.obj : error LNK2001: unresolved external symbol "class testing::internal::Mutex testing::internal::g_linked_ptr_mutex" (?g_linked_ptr_mutex@internal@testing@@3VMutex@12@A)
1>ConsoleApplication1.obj : error LNK2001: unresolved external symbol "class testing::internal::Mutex testing::internal::g_gmock_mutex" (?g_gmock_mutex@internal@testing@@3VMutex@12@A)
1>d:\Develop\CPP\ConsoleApplication1\Debug\ConsoleApplication1.exe : fatal error LNK1120: …Run Code Online (Sandbox Code Playgroud)