将Test Suite设置为忽略

adr*_*ale 6 java junit junit4 test-suite

我有很多测试套件,每个测试套件包含许多测试类.这是他们的样子:

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

    }
}
Run Code Online (Sandbox Code Playgroud)

有时我想完全禁用整个测试套件.我不想将每个测试类设置为@Ignore,因为每个测试套件都使用@BeforeClass和加载和释放资源,@AfterClass并且我想在忽略测试套件时跳过此加载/释放.

所以问题是:@Ignore我可以在整个测试套件上使用类似的东西吗?

Mat*_*ell 8

您可以使用注释来注释TestSuite @Ignore.

@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");
    }
}
Run Code Online (Sandbox Code Playgroud)

不产生任何输出.