SetUp
Test1
TearDown
SetUp
Test2
TearDown
TestFixtureTearDown
如果Test2單獨執行輸出的結果將是:
TestFixtureSetUp
SetUp
Test2
TearDown
TestFixtureTearDown
Test Attribute簡介
Test attribute主要用來標示在text fixture中的method,表示這個method需要被Test Runner application所執行。有Test attribute的method必須是public的,并且必須return void,也沒有任何傳入的參數。如果沒有符合這些規定,在Test Runner GUI之中是不會列出這個method的,而且在執行Unit Test的時候也不會執行這個method。上面的程序代碼示范了使用這個attribute的方法。
SetUp 和 Teardown Attributes簡介
在寫Unit Tests的時候,有時你會需要在執行每一個test method之前(或之后)先作一些預備或善后工作。當然,你可以寫一個private的method,然后在每一個test method的一開頭或最末端呼叫這個特別的method;蛘,你可以使用我們要介紹的SetUp及Teardown Attributes來達到相同的目的。如同這兩個Attributes的名字的意思,有Setup Attribute的method會在該TextFixture中的每一個test method被執行之前先被Test Runner所執行,而有Teardown Attribute的method則會在每一個test method被執行之后被Test Runner所執行。一般來說,Setup Attribute及Teardown Attribute被用來預備一些必須的objects(對象),例如database connection、等等。上面的程序代碼示范了使用這個attribute的方法。
ExpectedException Attributes簡介
文章來源于領測軟件測試網 http://www.kjueaiud.com/