2015-03-02 57 views
0

我正在嘗試將測試的常用功能寫入單獨的dll。當我這樣做時,我會按預期得到測試失敗的報告,但最終報告會說測試通過了。導出gtest函數導致失敗的測試通過

[==========] 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(); 
} 

有什麼事我做不正確的,當涉及到出口谷歌測試?我允許甚至做到這一點(請說是)?

編輯:我相信問題的一部分與UnitTest單身人士有關。 我編輯了我的代碼示例以更好地說明問題。指向UnitTest對象的指針應該是相同的,但它不是。任何想法發生了什麼?

+0

請參閱Google問答FAQ中的[此問題](https://code.google.com/p/googletest/wiki/FAQ#I_put_my_tests_in_a_library_and_Google_Test_doesn%27t_run_the)。 – 2015-03-03 01:17:06

+0

@AndréSassi謝謝。 Visual C++的錯誤不是問題,但我沒有建立我的gtest庫作爲DLL,這是問題。 – ASxa86 2015-03-03 14:32:27

回答

0

正如AndreSassi的評論中所發表的那樣。 GTest Primer FAQ解釋說,如果要將自己的DLL鏈接到主測試可執行文件,則必須將gtest庫編譯爲DLL。

我使用的是Visual Studio 2012,並且FAQ中提到的錯誤似乎不是問題。只是我沒有將gtest編譯爲DLL。

相關問題