[英]Boost Unit Test start but not execute
我寫了一些簡單的提升測試。 測試編譯,但啟動它不會執行測試主體。 下面是一個測試的例子。
// Windows uses Boost static libraries
#ifndef _WIN32
#define BOOST_TEST_DYN_LINK
#endif
#define BOOST_TEST_MODULE "SimpleTest"
#include <boost/test/unit_test.hpp>
#include "radarInterface/ObjConfiguration.h"
#include "radarInterface/ObjIF.h"
#include "CommonFunctions.h"
#ifndef BOOST_TEST
#define BOOST_TEST(A)
#endif
BOOST_AUTO_TEST_SUITE(_obj_interface_)
BOOST_AUTO_TEST_CASE(init_string)
{
BOOST_TEST_MESSAGE("init_string");
ObjConfiguration conf;
conf.mcastAddress("225.0.0.40");
conf.mcastPort(6310);
conf.ipAddress("127.0.0.1");
conf.tcpPort(6312);
BOOST_TEST(conf.isComplete() == true);
ObjIF objIf;
BOOST_CHECK_NO_THROW(objIf.init(conf));
usleep(3000000);
ri.fini();
}
BOOST_AUTO_TEST_SUITE_END()
嘗試運行它看起來一切都很好,但實際上測試機構沒有運行。 我使用 CMake 來編譯和運行測試。 以下是編譯后使用 CMake (ctest) 運行測試的結果。
Test project C:/Users/kongrosian/SimpleTest/build
Start 1: ObjInterface_test
1/1 Test #1: ObjInterface_test .............. Passed 0.03 sec
100% tests passed, 0 tests failed out of 1
Total Test time (real) = 0.05 sec
即使從命令行運行它似乎也不起作用。 使用命令
".\ObjInterface_test.exe --log_level=message --run_test=init_string"
我希望至少看到"init string"
消息。 相反,我只是得到
Process PID: xxxx
如果我在我的項目中使用 sehe 在評論中編寫的測試代碼,結果是一樣的。 執行命令時
./sotest --log_level=message --run_test=_obj_interface_/init_string
或者
./sotest --list_content
我得到Process PID: xxxx
作為命令行 output。
您對為什么會出現這種行為有任何想法嗎? 我使用的 boost 版本是 1.72。
我希望我已經澄清得更好。
目前尚不清楚您是如何得出測試未運行的結論的。 它似乎明確聲明它正在運行測試(並通過)。
但是,所消耗的時間與您的預期不符,這會導致您猜測您可能正在運行錯誤的目標(舊構建,例如不是最新的構建配置之一)。
給定測試套件名稱,命令行參數應如下所示:
./sotest --log_level=message --run_test=_obj_interface_/init_string
對我來說打印:
Running 1 test case...
init_string
*** No errors detected
如果需要,您可以使用一些通配符:
./sotest -l all -t "*/init_string" Running 1 test case... Entering test module "SimpleTest" /home/sehe/Projects/stackoverflow/test.cpp(20): Entering test suite "_obj_interface_" /home/sehe/Projects/stackoverflow/test.cpp(22): Entering test case "init_string" init_string /home/sehe/Projects/stackoverflow/test.cpp(45): info: check conf.isComplete() == true has passed /home/sehe/Projects/stackoverflow/test.cpp(53): info: check 'no exceptions thrown by objIf.init(conf)' has passed /home/sehe/Projects/stackoverflow/test.cpp(22): Leaving test case "init_string"; testing time: 3000212us /home/sehe/Projects/stackoverflow/test.cpp(20): Leaving test suite "_obj_interface_"; testing time: 3000270us Leaving test module "SimpleTest"; testing time: 3000294us *** No errors detected
使用--list_content
來...列出內容:
sehe ~ Projects stackoverflow ./sotest --list_content _obj_interface_* init_string*
保留以下划線開頭的名稱(或包含雙 __ 下划線)。 使用它們會使您的程序格式不正確,您可能會遇到問題。 請參閱關於在 C++ 標識符中使用下划線的規則是什么?
因此,您可能應該更改測試套件的名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.