【问题标题】:Setting Test Suite to Ignore将测试套件设置为忽略
【发布时间】:2012-06-15 02:20:00
【问题描述】:

我有许多测试套件,每个测试套件都包含许多测试类。它们的外观如下:

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 的东西可以用于整个测试套件吗?

【问题讨论】:

    标签: java junit junit4 test-suite


    【解决方案1】:

    您可以使用 @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");
        }
    }
    

    不产生任何输出。

    【讨论】:

      【解决方案2】:

      SlowTest 是一个由用户定义的类。它可以是空的(没有任何函数或属性)。你可以随意命名:

      【讨论】:

        猜你喜欢
        • 2011-07-27
        • 1970-01-01
        • 2018-07-07
        • 2020-04-14
        • 1970-01-01
        • 2017-05-11
        • 2020-11-29
        • 1970-01-01
        • 2019-09-30
        相关资源
        最近更新 更多