Home > The Unit Test Framework > User's guide > Test organization > Test suite >

Test suite

If you consider test cases as leaves on the test tree, the test suite can be considered as branch and the master test suite as a trunk. Unlike real trees though, our tree in many cases consists only of leaves attached directly to the trunk. This is common for all test cases to reside directly in the master test suite. If you do want to construct a hierarchical test suite structure the UTF provides both manual and automated test suite creation and registration facilities:
如果將測試用例當作測試樹的葉,那麼測試套件就是樹枝,主測試套件就是樹幹。 但是和真實的樹不同,我們的樹在很多情況下只包含樹葉,直接連在樹幹上。 所有的測試用例直接屬於主測試套件是很平常的。 如果你確實想要構造層次化的測試套件結構,UTF 同時提供了手動和自動創建註冊測試套件的工具:

Test unit registration interface

The UTF models the notion of test case container - test suite - using class boost::unit_test::test_suite. For complete class interface reference check advanced section of this documentation. Here you should only be interested in a single test unit registration interface:
UTF 將測試用例容器的概念建模為 - 測試套件 - 使用 boost::unit_test::test_suite 類。 完整的類接口參考請參見文檔的高級部分。 這裡你只需要關注單個測試單元註冊接口:

void test_suite::add( test_unit* tc, counter_t expected_failures = 0, int timeout = 0 );

The first parameter is a pointer to a newly created test unit. The second optional parameter - expected_failures - defines the number of test assertions that are expected to fail within the test unit. By default no errors are expected.
第一個參數是指向新創建的測試單元的指針。第二個可選的參數 - expected_failures - 定義了在測試單元中期望失敗的測試斷言數量。默認不期望碰到錯誤。

[Caution] Caution

Be careful when supplying a number of expected failures for test suites. By default the UTF calculates the number of expected failures in test suite as the sum of appropriate values in all test units that constitute it. And it rarely makes sense to change this.
為測試套件提供期望失敗數量要小心。因為 UTF 計算所有測試單元失敗數量的和與測試套件的期待失敗數量比較。並且這種做法可能不會改變。

The third optional parameter - timeout - defines the timeout value for the test unit. As of now the UTF isn't able to set a timeout for the test suite execution, so this parameter makes sense only for test case registration. By default no timeout is set. See the method boost::execution_monitor::execute for more details about the timeout value.
第三個可選參數 - timeout - 定義了測試單元的超時時間。 現在 UTF 還不支持設置測試套件的執行超時,所以這個參數只在註冊測試用例時有意義。 默認不設置超時時間。 關於超時時間更多的細節請參見方法 boost::execution_monitor::execute

To register group of test units in one function call the boost::unit_test::test_suite provides another add interface covered in the advanced section of this documentation.
要在一個函數中註冊一組測試單元,調用 boosot::unit_test::test_suite 提供的另外一個添加接口,在文檔高級部分有介紹。