Home > The Unit Test Framework > User's guide > Fixtures > Generic model

Generic fixture model

The UTF defines the generic fixture model as follows:
UTF 定義通用夾具模型如下:

struct <fixture-name>{
   <fixture-name>(); // setup function
   ~<fixture-name>(); // teardown function

In other words a fixture is expected to be implemented as a class where the class constructor serves as a setup method and class destructor serves as teardown method. The UTF opted to avoid explicit names in fixture interface for setup and teardown methods, since is considered most natural in C++ for tasks similar to RAII and coincides with the pure C++ solution discusses earlier.
換句話說,夾具期望被實現為類,類的構造函數是安裝方法,類的析構函數是拆卸方法。 UTF 避免在夾具接口中顯式定義安裝和拆卸方法, 因為就像之前討論的純 C++ 解決方案,RAII 是最 C++ 的解決方案。

[Important] Important

The above interface prevents you to report errors in the teardown procedure using an exception. It does make sense though: if somehow more than one fixture is assigned to a test unit, you want all teardown procedures to run, even if some may experience problems.
上面的接口不允許你在拆卸過程中使用異常報告錯誤。這是有意義的: 如果多於一個夾具被指定到一個測試單元,那麼即使碰到問題你也希望所有的拆卸過程都執行。