boost - 在Boost.Test中,如何获取当前测试的名称?

标签 boost boost-test

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/

相关文章:

c++ - 如何运行 Boost Test 并生成 Minidump?

c++ - 函数拒绝在 Boost 测试函数中工作

c++ - 使用 Boost.Serialization 进行序列化

c++ - boost 随机生成器返回相同的值

c++ - xubuntu 中对 boost::program_options 的 undefined reference

c++ - 访问 Boost 测试类 - test_results 和 results_collector

c++ - boost C++ : how to return file from folder via tcp?

c++ - 在 VC++ 2010 项目中使用 Boost 序列化库

c++ - Boost.Spirit 的单元测试

c++ - 在 Eclipse 中调试 Boost.Test : debugger won't stop at break points