Home > The Unit Test Framework > Testing tools >
PrevNext

The UTF testing tools or tester's toolbox for all occasions

Table of Contents

Output testing tool
Custom predicate support
Floating-point comparison algorithms
Reference

Introduction

The UTF's supplies a toolbox of testing tools to ease creation and maintenance of test programs and provide a uniform error reporting mechanism. The toolbox supplied in most part in a form of macro and function declarations. While the functions can be called directly, the usual way to use testing tools is via convenience macros. All macros arguments are calculated once, so it's safe to pass complex expressions in their place. All tools automatically supply an error location: a file name and a line number. The testing tools are intended for unit test code rather than library or production code, where throwing exceptions, using assert(), boost::concept_check or BOOST_STATIC_ASSERT() may be more suitable ways to detect and report errors. For list of all supplied testing tools and usage examples see the reference.
UTF 提供了一系列測試工具用於減輕創建和維護測試程序的任務, 並提供一致的錯誤報告機制。大部分工具以宏和函數定義的形式提供。 雖然函數可以被直接調用,但更常用的方式是通過方便的宏。 所有的宏參數都只計算一次,所以傳入複雜的表達式也是安全的。 所有的工具都自動提供錯誤位置:文件名和行號。 測試工具用於單元測試代碼而不是庫或產品級代碼,在那些代碼中,拋出異常,使用 assert(),boost::concept_checkBOOST_STATIC_ASSERT() 更適合於檢測和報告錯誤。 測試工具列表和使用示例請見參考。

Testing tools flavors

All the tools are supplied in three flavors(levels): WARN, CHECK and REQUIRE. For example: BOOST_WARN_EQUAL, BOOST_CHECK_EQUAL, BOOST_REQUIRE_EQUAL. If an assertion designated by the tool passes, confirmation message can be printed in log output[6]. If an assertion designated by the tool failed, depending on the level following will happened[7]:
所有測試工具都以三種味道 (級別) 提供: WARN, CHECKREQUIRE。 例如:BOOST_WARN_EQUALBOOST_CHECK_EQUALBOOST_REQUIRE_EQUAL。 如果斷言由通過工具指定,確認信息將打印在日誌輸出[6]中。 如果斷言由失敗工具指定,根據級別會產生如下結果[7]

Table 5. Testing tools levels differences

Level Test log content Errors counter Test execution
WARN warning in <test case name>: condition <assertion description> is not satisfied not affected continues
CHECK error in <test case name>: test <assertion description> failed increased continues
REQUIRE fatal error in <test case name>: critical test <assertion description> failed increased aborts

Regularly you should use CHECK level tools to implement your assertions. You can use WARN level tools to validate aspects less important then correctness: performance, portability, usability etc. You should use REQUIRE level tools only if continuation of the test case doesn't make sense if this assertions fails.
通常應該使用 CHECK 級別的工具實現斷言。可以使用 WARN 級別的工具來驗證不如正確性重要的方面:性能、可移植性、可用性等。 只有當斷言失敗時,後面的測試用例沒有意義的情況下才使用 REQUIRE 級別工具。



[6] to manage what messages appear in the test log stream set the proper log level
設置合適的日誌級別來管理哪些信息出現在測試日誌流中

[7] in some cases log message can be slightly different to reflect failed tool specifics
在某些情況下,反應失敗工具的日誌信息可能稍微不同


PrevUpHomeNext