C++ 导出gtest函数会导致失败的测试通过
我正在尝试将常用的测试功能写入一个单独的dll。当我这样做时,我会得到预期的测试失败报告,但最终报告会说测试通过了C++ 导出gtest函数会导致失败的测试通过,c++,c++11,googletest,C++,C++11,Googletest,我正在尝试将常用的测试功能写入一个单独的dll。当我这样做时,我会得到预期的测试失败报告,但最终报告会说测试通过了 [==========] Running 1 test from 1 test case. [----------] Global test environment set-up. [----------] 1 test from MyFoo [ RUN ] MyFoo.fooTest C:\Foo\Foo.cpp(2): error: Value of: false
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from MyFoo
[ RUN ] MyFoo.fooTest
C:\Foo\Foo.cpp(2): error: Value of: false
Actual: false
Expected: true
[ OK ] MyFoo.fooTest (0 ms)
[----------] 1 test from MyFoo(0 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[ PASSED ] 1 test.
正如你所看到的,测试失败了,但是报告说它通过了
这是我导出的函数的一个简单示例:
// Foo.dll
// Foo.h
FOO_EXPORT void Foo();
// Foo.cpp
#include <Foo.h>
#include <gtest/gtest.h>
void Foo()
{
::testing::UnitTest::GetInstance(); // 0x000007fecef5a590
EXPECT_TRUE(false);
}
这是我的gtest可执行文件的一个简单示例:
// TestMyFoo.exe
#include <Foo.h>
#include <gtest/gtest.h>
TEST(MyFoo, fooTest)
{
::testing::UnitTest::GetInstance(); // 0x000000003f9419d8
Foo();
}
在导出google测试时,我是否做得不对?我可以这样做吗?请说可以
编辑:我相信部分问题与UnitTest singleton有关。
为了更好地说明这个问题,我编辑了我的代码示例。指向UnitTest对象的指针应该相同,但不是。你知道这是怎么回事吗?安德烈萨西在评论中写道。说明如果要将自己的DLL链接到主测试可执行文件,则必须将gtest库编译为DLL
我使用的是Visual Studio 2012,常见问题解答中提到的bug似乎不是问题。只是我没有将gtest构建为DLL。请参见谷歌测试常见问题。@AndréSassi谢谢。VisualC++错误不是问题,但我并没有把我的GTestCub构建成DLL,这是个问题。