Java 多次运行特定的JUnit测试,但将其他测试排除在外

Java 多次运行特定的JUnit测试,但将其他测试排除在外,java,unit-testing,junit,junit4,Java,Unit Testing,Junit,Junit4,我正在使用参数化的JUnit runner多次运行一些测试。这是我的测试类的模板 @RunWith(value = Parameterized.class) public class TestClass { private String key; private boolean value; public TestClass(String key, boolean value) { this.key = key; this.value

我正在使用参数化的JUnit runner多次运行一些测试。这是我的测试类的模板

@RunWith(value = Parameterized.class)
public class TestClass {

    private String key;
    private boolean value;

    public TestClass(String key, boolean value) {
        this.key = key;
        this.value = value;
    }

    @Parameters
    public static Collection<Object[]> data() {
        Object[][] data = new Object[][] {
            {"key1", true},
            {"key2", true},
            {"key3", false}
        };
        return Arrays.asList(data);
    }

    @Test
    public void testKeys() {
        ...
    }

    @Test
    public void testValues() {
        ...
    }

    @Test
    public void testNotRelatedKeyValue() {
    }
}
@RunWith(值=参数化的.class)
公共类TestClass{
私钥;
私有布尔值;
公共TestClass(字符串键,布尔值){
this.key=key;
这个值=值;
}
@参数
公共静态收集数据(){
对象[][]数据=新对象[][]{
{“key1”,true},
{“key2”,true},
{“key3”,false}
};
返回数组.asList(数据);
}
@试验
公共void testKeys(){
...
}
@试验
公共void testValues(){
...
}
@试验
public void testNotRelatedKeyValue(){
}
}
现在,我希望我的测试方法-
testKeys(),testValues()
使用它们正在运行的不同参数值运行

然而,我发现我的最后一个方法-
testNotRelatedKeyValue()
也与其他参数化测试一起执行了很多次

我不希望
testNotRelatedKeyValue()
运行多次,只运行一次


在这个类中是否可能,或者我是否需要创建一个新的测试类?

您可以使用


您可以使用


看看这个:所以基本上,我必须将我的测试类划分为单独的测试类和
Suite
特性来运行它们。没有任何直接的方法。如果你想让测试成为同一个类的一部分,那么这是推荐的方法。看看这个:所以基本上,我必须将我的测试类拆分为单独的测试类和
Suite
功能来运行它们。没有任何直接的方法,如果你想让测试成为同一个类的一部分,那么这是推荐的方法。
@RunWith(Enclosed.class)
public class TestClass {

    @RunWith(Parameterized.class)
    public static class TheParameterizedPart {
        @Parameter(0)
        public String key;

        @Parameter(1)
        private boolean value;

        @Parameters
        public static Object[][] data() {
            return new Object[][] {
                {"key1", true},
                {"key2", true},
                {"key3", false}
            };
        }

        @Test
        public void testKeys() {
            ...
        }

        @Test
        public void testValues() {
            ...
        }
    }

    public static class NotParameterizedPart {
        @Test
        public void testNotRelatedKeyValue() {
            ...
        }
    }
}