Home > The Unit Test Framework > User's guide > Usage variants > Single header

The single-header variant of the UTF

If you prefer to avoid the standalone library compilation, you should use the single-header variant of the UTF. This variant is implemented, as it follows from its name, in the single header boost/test/included/unit_test.hpp. An inclusion of the header causes the complete implementation of the UTF to be included as a part of a test module's source file. The header boost/test/unit_test.hpp doesn't have to be included anymore. You don't have to worry about disabling auto-linking feature either. It's done in the implementation header already. This variant can't be used with the multi-file test module. Otherwise it's almost identical from the usage prospective to the static library variant of the UTF. In fact the only difference is the name of the include file: boost/test/included/unit_test.hpp instead of boost/test/unit_test.hpp.
如果你不想編譯獨立庫,你可以使用 UTF 的單頭文件用法。 這種用法,就像名字顯示的,實現在單個頭文件 boost/test/included/unit_test.hpp 中。 包含這個頭文件會導致 UTF 的完全實現被作為測試模塊源文件的一部分。 頭文件 boost/test/unit_test.hpp 不需要再被包含。 你同樣不需要為關閉自動鏈接特性而煩惱。 它已經在頭文件中被實現了。 這種方法不能被應用於多文件測試模塊。 否則它就和 UTF 靜態庫的用法一樣了。 實際上,唯一的差別是包含文件的名稱:用 boost/test/included/unit_test.hpp 替換 boost/test/unit_test.hpp

The test runner supplied with this variant requires you to implement the test module initialization function that matches one of the two specifications depending on the compilation flag BOOST_TEST_ALTERNATIVE_INIT_API. If flag isn't defined you are required to match the original specification. If you define the flag BOOST_TEST_ALTERNATIVE_INIT_API during a test module compilation you are required to use the alternative initialization function specification. The UTF provides an ability to automatically generate an empty test module initialization function with correct specification if no custom initialization is required by a test module.
這種用法提供的測試運行器需要你根據編譯標籤 BOOST_TEST_ALTERNATIVE_INIT_API 實現測試模塊匹配兩種定義之一的初始化函數。 如果在測試模塊編譯過程中定義了標籤 BOOST_TEST_ALTERNATIVE_INIT_API,你需要使用備選的初始化函數定義。 如果測試模塊不需要自定義的初始化,UTF 提供了自動生成正確的空測試模塊初始化函數的能力。