Boost unit test - list of available tests

I wrote several scripts to automate the work of our unit tests, written using the enhancement module testing platform. I would like to add functionality to allow the selection and subsequent execution of a subset of all tests. I know that I can run a subset of the tests using the run_test argument, but I cannot find a way to list all the tests that are in the compiled binary, that is, all the argument values ​​that I can pass to run_test. Is there a way to extract all available tests, or do I need to write my own test runner? If so, where to start?

+4
source share
2 answers

The documentation for the internal components of boost :: test may be a little inadequate, and it says that everything is available.

Look at the boost :: test header files, in particular for the test_suite and test_unit classes. There is a function called traverse_test_tree that can be used to pass registered tests.

Below is some samle code that I wrote to display the test results in a specific format, it uses traverse_test_tree to display the result of each test, I hope that it gives you a start.

/** * Boost test output formatter to output test results in a format that * mimics cpp unit. */ class CppUnitOpFormatter : public boost::unit_test::output::plain_report_formatter { public: /** * Overidden to provide output that is compatible with cpp unit. * * \param tu the top level test unit. * \param ostr the output stream */ virtual void do_confirmation_report( boost::unit_test::test_unit const& tu, std::ostream& ostr ); }; class CppUnitSuiteVisitor : public test_tree_visitor { public: explicit CppUnitSuiteVisitor( const string& name ) : name_( name ) {} virtual void visit( const test_case& tu ) { const test_results& tr = results_collector.results( tu.p_id ); cout << name_ << "::" << tu.p_name << " : " << ( tr.passed() ? "OK\n" : "FAIL\n" ); } private: string name_; }; // ---------------------------------------------------------------------------| void CppUnitOpFormatter::do_confirmation_report( test_unit const& tu, std::ostream& ostr ) { using boost::unit_test::output::plain_report_formatter; CppUnitSuiteVisitor visitor( tu.p_name ); traverse_test_tree( tu, visitor ); const test_results& tr = results_collector.results( tu.p_id ); if( tr.passed() ) { ostr << "Test Passed\n"; } else { plain_report_formatter::do_confirmation_report( tu, ostr ); } } 
+4
source

The external version of Boost.Test has a command line argument to get what you need.

+2
source

Source: https://habr.com/ru/post/1386905/


All Articles