2012-06-12 71 views
4

我有很多測試套件,每個套件都包含很多測試類。下面是它們的外觀:設置測試套件忽略

import org.junit.AfterClass; 
import org.junit.BeforeClass; 
import org.junit.runner.RunWith; 
import org.junit.runners.Suite; 
import org.junit.runners.Suite.SuiteClasses; 

@RunWith(Suite.class) 
@SuiteClasses({ATest.class, BTest.class}) 
public class MyFirstTestSuite { 

    @BeforeClass 
    public static void beforeClass() throws Exception { 
       // load resources 
    } 

    @AfterClass 
    public static void afterClass() throws Exception { 
     // release resources 

    } 
} 

有時我想完全禁用整個測試套件。我不想將每個測試類設置爲@Ignore,因爲每個測試套件都使用@BeforeClass@AfterClass加載和釋放資源,並且當忽略測試套件時,我想跳過此加載/釋放。

所以問題是:是否有類似於@Ignore的東西,我可以在整個測試套件上使用?

回答

7

您可以使用@Ignore註釋TestSuite。

@RunWith(Suite.class) 
@SuiteClasses({Test1.class}) 
@Ignore 
public class MySuite { 
    public MySuite() { 
     System.out.println("Hello world"); 
    } 

    @BeforeClass 
    public static void hello() { 
     System.out.println("beforeClass"); 
    } 
} 

不會產生任何輸出。

+0

它的工作。謝謝! – adranale

0

SlowTest是用戶定義的類。它可以是空的(沒有任何功能或屬性)。你可以命名爲任何你想要的:

enter image description here

enter image description here