让所有升压测试套件/测试用例 [英] getting all boost test suites / test cases

查看:150
本文介绍了让所有升压测试套件/测试用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说,我想从一个测试应用程序的所有测试套件或测试用例(名称),在控制台或XML输出​​醚。
测试框架是升压测试库。

As the title says, I want to get all test suites or test cases (name) from a test application, ether in the console or as xml output. Test framework is the boost test library.

有没有办法做到这一点的选项?我没有发现任何的文档中非常有用。

Is there an option to achieve this? I did not found anything useful in the documentation.

推荐答案

这可没有太多的侵扰使用<一做href=\"http://www.boost.org/doc/libs/1_60_0/libs/test/doc/html/boost_test/tests_organization/fixtures/global.html\"相对=nofollow>全球夹具。假设你有一个翻译单元(CPP文件),其中包含明示或产生,提供了一定的命令行参数的时候,你可以拦截测试执行的汽车。然后你就可以使用定制的游客,其中列出了所有可用的测试遍历测试树。这里是一个小工作的例子,它通过编译和链接的文件创建一个测试运行 main_test.cpp a.cpp b.cpp

This can be done without much intrusion using a global fixture. Assuming you have a translation unit (cpp file) that contains main explicitly or auto generated, you can intercept test execution when a certain command line argument is provided. Then you can traverse the test tree using a customized visitor, which lists all available tests. Here is a small working example, which creates a test runner by compiling and linking files main_test.cpp, a.cpp and b.cpp:

main_test.cpp

#include <string>
#include <iostream>

// --- Boost Includes ---
#define BOOST_TEST_MODULE MyTestSuite
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>

using namespace boost::unit_test;

struct Visitor : test_tree_visitor
{
  size_t level = 0;

  void visit( test_case const& test )
  {
    std::string indentation( level, '.' );

    std::cout << indentation << test.p_name << std::endl;
  }

  bool test_suite_start( test_suite const& suite )
  {
    std::string indentation( level, '.' );
    level++;

    std::cout << indentation << "Suite: " << suite.p_name << std::endl;
    return true;
  }

  void test_suite_finish( test_suite const& suite )
  {
    level--;
  }
};

struct GlobalFixture
{
  GlobalFixture( )
  {
    int argc = framework::master_test_suite( ).argc;
    for ( int i = 0; i < argc; i++ )
    {
      std::string argument( framework::master_test_suite( ).argv[i] );

      if ( argument == "list" )
      {
        Visitor visitor;

        traverse_test_tree( framework::master_test_suite( ), visitor );

        exit( EXIT_SUCCESS );
      }
    }
  }

};

BOOST_GLOBAL_FIXTURE( GlobalFixture )

a.cpp

#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE ( TestA )

BOOST_AUTO_TEST_CASE ( TestFoo )
{
  BOOST_CHECK(true);
}

BOOST_AUTO_TEST_CASE ( TestBar )
{
  BOOST_CHECK(true);
}

BOOST_AUTO_TEST_SUITE_END() // TestA

b.cpp

#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE ( TestB )

BOOST_AUTO_TEST_CASE ( TestFoo )
{
  BOOST_CHECK(true);
}

BOOST_AUTO_TEST_CASE ( TestBar )
{
  BOOST_CHECK(true);
}

BOOST_AUTO_TEST_SUITE_END() // TestA

调用亚军无任何参数结果

Invoking the runner without any arguments results in

./somelib_testrunner1 
Running 4 test cases...

*** No errors detected

传递参数列表

Suite: MyTestSuite
.Suite: TestA
..TestFoo
..TestBar
.Suite: TestB
..TestFoo
..TestBar

这篇关于让所有升压测试套件/测试用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆