How can I skip a BOOST unit test? I would like to programatically skip some of my unit tests depending on, (for instance) the platform on which I am executing them. My current solution is:
#define REQUIRE_LINUX char * os_cpu = getenv("OS_CPU"); if ( os_cpu != "Linux-x86_64" ) return;
BOOST_AUTO_TEST_CASE(onlylinux) {
REQUIRE_LINUX
...
the rest of the test code.
}
(note that our build environment sets the variable OS_CPU). This seems ugly and error-prone, and also like the silent skips could cause users to be skipping tests without knowing about it.
How can I cleanly skip boost unit tests based on arbitrary logic?
Run your tests in parallel I've already covered this in another blog post “PARALLELISM: NUNIT VS. XUNIT” that running your tests in parallel can significantly improve the speed of your test runs. Basically this means all your tests will run "next to each other" instead of "one by one".
Thus, a unit test suite used for TDD should run in less than 10 seconds. If it's slower, you'll be less productive because you'll constantly lose focus.
The Test Adapter for Boost. Test is a unit testing extension published by Microsoft and based on the existing Boost Unit Test Adapter (v1. 0.8) Visual Studio extension by Gunter Wirth's team from ETAS GmbH. This extension is developed in collaboration with the original project with the aim of improving Boost.
BOOST_AUTO_TEST_CASE(a_test_name,
*boost::unit_test::disabled()
)
{
...
}
Use enable_if / enable / precondition decorators.
boost::test_tools::assertion_result is_linux(boost::unit_test::test_unit_id)
{
return isLinux;
}
BOOST_AUTO_TEST_SUITE(MyTestSuite)
BOOST_AUTO_TEST_CASE(MyTestCase,
* boost::unit_test::precondition(is_linux))
{...}
precondition is evaluated at runtime, enable, enable_if at compile time.
See: http://www.boost.org/doc/libs/1_61_0/libs/test/doc/html/boost_test/tests_organization/enabling.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With