在Boost.Test
中,如何获取当前自动测试用例的名称?
例子:
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(MyTest)
{
std::cerr << "Starting " << test_name << std::endl;
// lots of code here
std::cerr << "Ending " << test_name << std::endl;
}
在示例中,我希望变量
test_name
包含“MyTest”。
最佳答案
有一个未记录的*函数可以为此目的而调用。以下行会将当前测试的名称刷新为cerr
:
#include <boost/test/framework.hpp>
...
std::cerr << boost::unit_test::framework::current_test_case().p_name
<< std::endl;
但是请注意,在进行参数化测试的情况下,使用此API不会刷新参数。
您可能也对test checkpoints **感兴趣(这似乎是您想要做的。)
#include <boost/test/included/unit_test.hpp>
...
BOOST_AUTO_TEST_CASE(MyTest)
{
BOOST_TEST_CHECKPOINT("Starting");
// lots of code here
BOOST_TEST_CHECKPOINT("Ending");
}
编辑
*现在记录了
current_test_case()
函数,请参阅the official Boost documentation。**
BOOST_TEST_CHECKPOINT
以前称为BOOST_CHECKPOINT
。参见Boost changelog (1.35.0)。
关于boost - 在Boost.Test中,如何获取当前测试的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10574400/