junit 4 測試回合器

來源:互聯網
上載者:User
        JUnit 中所有的測試方法都是由測試回合器負責執行。JUnit單元測試提供了一個預設的測試回合器BlockJunit4ClassRunner,但是並沒有限制必須使用預設的運行器。
我們可以根據需要定製自己的運行器,只要繼承自 org.junit.runner.Runner即可。一般情況下,預設測試回合器可以應對絕大多數的單元測試要求。當使用JUnit提供的一些進階特性(如實現參數化測試、實現打包測試或者針對特殊需求定製JUnit測試方式)時,則需要顯示地聲明測試回合器。如@RunWith(CustomerTestRunner.class)。 import static org.junit.Assert.*; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; /**  * @author Chris  *  */ @RunWith(Suite.class) @SuiteClasses({JunitExceptionTest.class,Junit4ParameterTest.class,JunitTimeoutTest.class}) public class JUnit4SuiteTest {  @Test  public void allTest(){   assertNotNull(null);  } } JUnit 為我們提供了打包測試的功能,將所有需要啟動並執行測試案例集中起來,一次性地運行所有測試案例,大大地方便了我們的測試工作。
通過@RunWith註解指定一個Suite測試回合器,另外通過@SuiteClasses註解將所有需要進行測試的用例打包起來。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.