Java 在测试套件中通过@ExcludeCategory忽略junit测试

Java 在测试套件中通过@ExcludeCategory忽略junit测试,java,testing,junit,continuous-integration,Java,Testing,Junit,Continuous Integration,我想运行包含各种测试类的Junit测试套件 在所有测试中,我想排除带有特定注释的测试方法 我知道@Ignore注释,但我不想在这里使用它,因为如果我从不同的测试套件调用测试,我希望能够忽略不同的测试方法 我试过了,但不起作用。 在不使用@ExcludeCategory(IgnoreMeForSpecialReason.class)的情况下运行我的套件运行的测试用例数量与使用@ExcludeCategory(IgnoreMeForSpecialReason.class)运行的测试用例数量相同 为了

我想运行包含各种测试类的Junit测试套件

在所有测试中,我想排除带有特定注释的测试方法

我知道@Ignore注释,但我不想在这里使用它,因为如果我从不同的测试套件调用测试,我希望能够忽略不同的测试方法

我试过了,但不起作用。 在不使用@ExcludeCategory(IgnoreMeForSpecialReason.class)的情况下运行我的套件运行的测试用例数量与使用@ExcludeCategory(IgnoreMeForSpecialReason.class)运行的测试用例数量相同

为了说明这一点:

这套房

//version 1
@RunWith(Categories.class)
@ExcludeCategory(IgnoreForSpecialReasonA.class)
@SuiteClasses({
    // add your test classes here
    Module1Test.class,
    Module2Test.class,
    Module3Test.class
})

public class MySuiteA
{

}
运行与此版本套件相同数量的测试:

//version 2
@RunWith(Categories.class)
//@ExcludeCategory(IgnoreForSpecialReasonA.class)
@SuiteClasses({
    // add your test classes here
    Module1Test.class,
    Module2Test.class,
    Module3Test.class
})

public class MySuiteA
{

}
Module1测试的一种测试方法用@IgnoreForSpecialReasonA注释进行注释。在我的示例的版本1中应该跳过该方法,但它已运行

如何实现@ExcludeCategory实际与套件一起工作


干杯

@excludecegory
应与
@Category
一起使用


确保使用
@Category(IgnoreForSpecialReasonA.class)

对您的ignore方法/类进行注释。就是这样,我只是直接注释了该方法,而不是通过@Category注释。谢谢