c++ - boost 。如何在另一个测试单元中运行一个测试单元?

标签 c++ unit-testing boost

我需要在当前单元的开头运行一个测试单元。 我已尝试 BOOST_TEST_INVOKE_IF_N_ARGS 但没有结果。

最佳答案

您可以manage test dependencies :

Decorator depends_on associates the decorated test case (call it TB) with another test case (call it TA) specified by name. This affects the processing the test tree in two ways. First, test case TA is ordered to be run before TB, irrespective of the order in which they were declared or added to the test tree. Second, the execution of TB is skipped if TA is either disabled or skipped or is executed and marked as failed.

#define BOOST_TEST_MODULE decorator_07
#include <boost/test/included/unit_test.hpp>

namespace utf = boost::unit_test;

// test1 and test2 defined at the bottom

BOOST_AUTO_TEST_CASE(test3, * utf::depends_on("s1/test1"))
{
  BOOST_TEST(false);
}

BOOST_AUTO_TEST_CASE(test4, * utf::depends_on("test3"))
{
  BOOST_TEST(false);
}

BOOST_AUTO_TEST_CASE(test5, * utf::depends_on("s1/test2"))
{
  BOOST_TEST(false);
}

BOOST_AUTO_TEST_SUITE(s1)

  BOOST_AUTO_TEST_CASE(test1)
  {
    BOOST_TEST(true);
  }

  BOOST_AUTO_TEST_CASE(test2, * utf::disabled())
  {
    BOOST_TEST(false);
  }

BOOST_AUTO_TEST_SUITE_END()

打印

> decorator_07 --report_level=detailed
Running 4 test cases...
test.cpp(10): error: in "test3": check false has failed

Test module "decorator_07" has failed with:
  1 test case out of 4 passed
  1 test case out of 4 failed
  2 test cases out of 4 skipped
  1 assertion out of 2 passed
  1 assertion out of 2 failed

  Test case "test3" has failed with:
    1 assertion out of 1 failed

  Test case "test4" was skipped
  Test case "test5" was skipped
  Test suite "s1" has passed with:
    1 test case out of 1 passed
    1 assertion out of 1 passed

    Test case "s1/test1" has passed with:
      1 assertion out of 1 passed

关于c++ - boost 。如何在另一个测试单元中运行一个测试单元?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51377250/

相关文章:

c++ - 从整数列表中选择一个随机数

c# - 对 WCF 服务的身份验证未使用 SetAuthCookie 和完整的 .net 客户端维护,但可与 silverlight 一起使用

c++ - auto_ptr 与 shared_ptr 的性能对比

c++ - boost async_write : if it fails, 如何跟踪未发送的内容并通知客户端/用户失败的内容?

c++ - 为 Crypto++ 构建和链接测试代码

c++ - 实现 : private structs in Class

c++ - "In file included from error"带 vector

objective-c - 我如何在 OCMock 中模拟接受句柄作为参数的方法?

c++ - Google 使用全局 vector 测试 ValuesIn

visual-c++ - 如何将 MFC CString 与 boost 字符串算法库一起使用