Home > The Unit Test Framework > User's guide > Test organization > Nullary function based test case > Automated registration
PrevNext

Nullary function based test case with automated registration

To create a nullary free function cased test case, which is registered in place of implementation, employ the macro BOOST_AUTO_TEST_CASE.
要創建實現時即註冊的基於無參自由函數的測試用例,使用宏 BOOST_AUTO_TEST_CASE。

BOOST_AUTO_TEST_CASE(test_case_name)

The macro is designed to closely mimic nullary free function syntax. Changes that are required to make an existing test case, implemented as a free function, registered in place are illustrated in the following example (compare with Example 5, 「Nullary free function manually registered」):
宏設計為模仿無參自由函數語法。下面示例的變化是為了將存在的測試用例用自由函數實現,並即時地註冊 (同Example 5, 「Nullary free function manullary register」 比較):

Example 10. Nullary function based test case with automated registration

#define BOOST_TEST_MODULE example
#include <boost/test/included/unit_test.hpp>

//____________________________________________________________________________//

BOOST_AUTO_TEST_CASE( free_test_function )
{
    BOOST_CHECK( true /* test assertion */ );
}

//____________________________________________________________________________//

Source code | Show output
> example --log_level=test_suite
Running 1 test case...
Entering test suite "example"
Entering test case "free_test_function"
Leaving test case "free_test_function"; testing time: 16ms
Leaving test suite "example"

*** No errors detected

With this macro you don't need to implement the initialization function at all. The macro creates and registers the test case with the name free_test_function automatically.
使用這個宏需要不需要自己實現初始化函數。宏用 free_test_function 作為名稱自動創建並註冊測試用例。


PrevUpHomeNext