unit_test_example_05.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // (C) Copyright Gennadiy Rozental 2005-2014.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/test for the library home page.
  6. // Boost.Test
  7. #define BOOST_TEST_MODULE "Unit test example 05"
  8. #include <boost/test/unit_test.hpp>
  9. namespace bt = boost::unit_test;
  10. //____________________________________________________________________________//
  11. BOOST_AUTO_TEST_SUITE( my_suite )
  12. struct F {
  13. F() : i( 0 ) { BOOST_TEST_MESSAGE( "setup fixture" ); }
  14. ~F() { BOOST_TEST_MESSAGE( "teardown fixture" ); }
  15. int i;
  16. };
  17. //____________________________________________________________________________//
  18. // this test case will use struct F as fixture
  19. auto& d =
  20. * bt::enabled()
  21. * bt::expected_failures(1);
  22. BOOST_FIXTURE_TEST_CASE( my_test1, F )
  23. {
  24. // you have direct access to non-private members of fixture structure
  25. BOOST_TEST( i == 1 );
  26. }
  27. //____________________________________________________________________________//
  28. // you could have any number of test cases with the same fixture
  29. BOOST_FIXTURE_TEST_CASE( my_test2, F, * bt::depends_on("my_suite/my_test1") )
  30. {
  31. BOOST_TEST( i == 2 );
  32. BOOST_TEST( i == 0 );
  33. }
  34. //____________________________________________________________________________//
  35. BOOST_AUTO_TEST_SUITE_END()
  36. // EOF