1[/ 2 / Copyright (c) 2003 Boost.Test contributors 3 / 4 / Distributed under the Boost Software License, Version 1.0. (See accompanying 5 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 /] 7 8[section:test_organization_nullary Test cases without parameters] 9 10The most common scenario is that you want to write test case without any parameters. The __UTF__ provides you with both 11automatic and manual registration APIs to declare such test case. 12 13[#ref_BOOST_AUTO_TEST_CASE][h4 Automated registration] 14 15To declare a test case without parameters, which is registered in place of implementation, employ the 16macro __BOOST_AUTO_TEST_CASE__. 17 18`` 19 __BOOST_AUTO_TEST_CASE__(test_case_name); 20`` 21 22This API is designed to closely mimic nullary free function declaration syntax. 23In comparison with free function all you need to do is to skip result type and brackets and wrap test 24case name into BOOST_AUTO_TEST_CASE: 25 26[bt_example example06..Nullary function based test case with automated registration..run] 27 28With this macro you don't need to implement any other registration steps. The macro creates and 29registers the test case with the name `free_test_function` automatically. 30 31[#ref_BOOST_TEST_CASE][h4 Manual registration] 32 33The __UTF__ allows to manually create test case without parameters based on nullary free functions, nullary 34function objects (including those created with `boost::bind` and nullary `boost::function` 35instances). To do this, employ the macro __BOOST_TEST_CASE__: 36 37`` 38 BOOST_TEST_CASE(test_function); 39`` 40 41__BOOST_TEST_CASE__ creates an instance of the class [classref boost::unit_test::test_case] and returns a pointer to the 42constructed instance. The test case name is deduced from the macro argument test_function. If you prefer to 43assign a different test case name, you have either to 44 45* use the macro __BOOST_TEST_CASE_NAME__ instead 46* or use the underlying [headerref boost/test/tree/test_unit.hpp `make_test_case`] interface instead. 47 48To register a new test case, employ the method [memberref boost::unit_test::test_suite::add `test_suite::add`]. 49Both test case creation and registration are performed in the 50[link boost_test.adv_scenarios.test_module_init_overview test module initialization function]. 51 52Here is the simplest example of manually registered test case. A single test case is created and registered inside 53the test module initialization routine. Note that the free function name is passed by address to the macro __BOOST_TEST_CASE__`. 54 55[#ref_bt_example01] 56[bt_example example01..Nullary free function manually registered..run] 57 58A test case can be implemented as a method of a class. In this case a pointer to the class instance has to be 59bound to the test method to create a test case. You can use the same instance of the class for multiple test 60cases. The __UTF__ doesn't take an ownership of the class instance and you are required to manage the class 61instance lifetime yourself. 62 63[warning 64 The class instance can't be defined in the initialization function scope, since it becomes invalid as 65 soon as the test execution exits it. It needs to be either defined statically/globally or managed using a 66 shared pointer. 67] 68 69[bt_example example03..Nullary method of a class bound to shared class instance and manually registered..run-fail] 70 71[endsect] 72 73[/EOF] 74