gtest运行错误:目标配方'测试'失败

时间:2017-05-07 12:03:16

标签: cmake googletest

我使用gtest,当一个测试用例在类型

之后失败时发生了一些错误

$ make test

Running tests...
Test project /home/wangfrank/GitRootPath/qwer/http_server_client_practice/bin
    Start 1: case-2_nettools_test
1/3 Test #1: case-2_nettools_test .............***Failed    0.00 sec
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from test_case_2
[ RUN      ] test_case_2.test_ipv4addr_constructor
32512
/home/wangfrank/GitRootPath/qwer/http_server_client_practice/test/2_nettools_test.cpp:12: Failure
      Expected: ip_s_0
      Which is: "127.0.0.1"
To be equal to: ip_s_1
      Which is: "32512"
[  FAILED  ] test_case_2.test_ipv4addr_constructor (0 ms)
[----------] 1 test from test_case_2 (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] test_case_2.test_ipv4addr_constructor

 1 FAILED TEST

    Start 2: case-0_config_test
2/3 Test #2: case-0_config_test ...............   Passed    0.00 sec
    Start 3: case-1_facility_test
3/3 Test #3: case-1_facility_test .............   Passed    0.01 sec

67% tests passed, 1 tests failed out of 3

Total Test time (real) =   0.01 sec

The following tests FAILED:
          1 - case-2_nettools_test (Failed)
Errors while running CTest
Makefile:116: recipe for target 'test' failed
make: *** [test] Error 8

这就是我的CMakeLists.txt的样子:

 17 message("==== ENTRY ==== ${unittest_SOURCE_DIR}")                                                                                                                                                               
 18 file(GLOB TESTFILES ./ *.cpp)                                                                                                                                                                                   
 19 foreach(singletestfilename ${TESTFILES})                                                                                                                                                                        
 20     get_filename_component(tn ${singletestfilename} NAME_WE)                                                                                                                                                    
 21     message("==== do with file target : ${tn}")                                                                                                                                                                 
 22     add_executable(${tn} ${singletestfilename})                                                                                                                                                                 
 23     target_link_libraries(${tn} gtest gtest_main)                                                                                                                                                               
 24     target_link_libraries(${tn} ${MY_EXTRA_LIBS})                                                                                                                                                               
 25     add_test(NAME case-${tn}                                                                                                                                                                                    
 26         COMMAND ${tn})                                                                                                                                                                                          
 27 endforeach(singletestfilename)

以下是该测试文件。

  1 #include "nettools.h"                                                                                                                                                                                           
  2 #include "facility.h"                                                                                                                                                                                           
  3 #include "gtest/gtest.h"                                                                                                                                                                                        
  4                                                                                                                                                                                                                 
  5 TEST(test_case_2, test_ipv4addr_constructor) {                                                                                                                                                                  
  6     using my_http::Ipv4Addr;                                                                                                                                                                                    
  7     Ipv4Addr test_ip = Ipv4Addr("localhost", 1234);                                                                                                                                                             
  8     std::cout << test_ip.get_ip_str() << std::endl;                                                                                                                                                             
  9     std::string ip_s_0 = Ipv4Addr::host2ip_str("localhost");                                                                                                                                                    
 10     std::string ip_s_1 = test_ip.get_ip_str();                                                                                                                                                                  
 11     EXPECT_EQ(ip_s_0, ip_s_1);                                                                                                                                                                                  
 12 }                                                                                                                                                                                                               
 13                                                                                                                                                                                                                 
 14 int main(int argc, char **argv) {                                                                                                                                                                               
 15     ::testing::InitGoogleTest(&argc, argv);                                                                                                                                                                     
 16     return RUN_ALL_TESTS();                                                                                                                                                                                     
 17 }        

它在gtest中成为 issue 。但我还是不知道如何修复它?有人能给我一些帮助吗?

我使用的是ubuntu16.04,gcc5.4.0,cmake 3.5.1,gtest 1.7.0(我在gtest主目录下的CHANGES文件中找到的内容)。

------第二次编辑--------

如果测试没有失败,则没有错误。

如果我手动运行可执行文件,则没有错误。

0 个答案:

没有答案
相关问题