Home > The Unit Test Framework > Introduction


The acceptance test makes the customer satisfied that the software provides the business value that makes them willing to pay for it. The unit test makes the programmer satisfied that the software does what the programmer thinks it does

--XP maxim

What is the first thing you need to do when you start working on new library/class/program? That's right - you need to start with the unit test module (I hope you all gave this answer!). Occasional, simple test may be implemented using asserts. But any professional developer soon finds this approach lacking. It becomes clear that it's too time-consuming and tedious for simple, but repetitive unit testing tasks and it's too inflexible for most nontrivial ones.
你開始與新的庫 / 類 / 程序工具時首先要做什麼?對 - 你需要從單元測試模塊開始 (我希望你也這麼認為!)。 有些情況下,簡單的測試是用 assert 實現的。但專業的開發人員很快就會發現這個方法的不足。 很快就會清楚,這太耗時了,並且對於簡單但重複的單元測試任務來說太過繁瑣,對於大多數不平凡的情況來說又太缺乏彈性。

The Boost Test Library Unit Test Framework (further in the documentation referred by the acronym UTF) provides both an easy to use and flexible solution to this problem domain: C++ unit test implementation and organization.
The Boost Test Library Unit Test Framework (後面的文檔中使用縮寫 UTF) 為這個問題領域提供了簡單而可伸縮的解決方案:C++ 單元測試實現和組織。

Unit testing tasks arise during many different stages of software development: from initial project implementation to its maintenance and later revisions. These tasks differ in their complexity and purpose and accordingly are approached differently by different developers. The wide spectrum of tasks in a problem domain cause many requirements (sometimes conflicting) to be placed on a unit testing framework. These include:
單元測試任務會在軟件開發很多步驟中出現:從最初的工程實現,到維護,校審。 這些任務的複雜度、目的、開發者、實現方式都是不同的。 一個問題如此大範圍的任務會導致非常多的需求 (有時甚至是相互衝突的) 被應用於單元測試框架。包括:

The UTF design is based on above rationale and provides versatile facilities to:
UTF 就是基於上面的原理設計的,並且為下面的情況提供了全面的工具:

The UTF keeps track of all passed/failed testing tools assertions, provides an ability to check the test progress and generates a result report in several different formats. The UTF supplies command line test runners that initialize the framework and run the requested tests. Depending on the selected compilation flags the function main() default implementation, that invoke the supplied test runner, can be generated automatically as well.
UTF 知道所有成功 / 失敗的測試斷言 (assertion), 提供檢查測試進度和生成多種格式的結果報告的能力。 UTF 提供命令行測試運行工具用來初始化框架並運行需要的測試。 依賴於所選的編譯標籤 (compilation flag) 函數 main() 默認實現調用提供的測試運行工具,同樣會被自動生成。

The UTF is intended to be used both for a simple and non trivial testing. It is not intended to be used with production code. In this case the Program Execution Monitor is more suitable.
UTF 試圖用於簡單和非平凡的測試。它並不試圖應用於工業級代碼中。 在這種情況下 Program Execution Monitor 更適用。

Given the largely differing requirements of new and advanced users, it is clear that the UTF must provide both simple, easy-to-use interfaces with limited customization options and advanced interfaces, which allow unit testing to be fully customized. Accordingly the material provided in this documentation is split into two sections:
由於初學者和高級用戶之間巨大的需求差別,UTF 必須提供簡單、易於使用的、只可簡單配置的接口和允許全面配置單元測試的高級接口。 同樣,文檔中提供的材料也分為兩個部分:

For those interested in getting started quickly please visit collection of examples presented in this documentation.