Junit使用@parameter标记的参数运行所有测试

Junit使用@parameter标记的参数运行所有测试,junit,junit4,parameterized-unit-test,Junit,Junit4,Parameterized Unit Test,在下面的代码中,我想使用标有@parameters的参数运行TestMethod1 @RunWith(Parameterized.class) public class Foo{ private boolean input; private boolean expected; public Foo(boolean input, boolean expected{ this.input=input; this.expected=expected; } @Parameters publ

在下面的代码中,我想使用标有
@parameters
的参数运行
TestMethod1

    @RunWith(Parameterized.class)
public class Foo{

private boolean input;
private boolean expected;

public Foo(boolean input, boolean expected{
this.input=input;
this.expected=expected;
}

@Parameters
public static List<Object[]> data() {
        return Arrays.asList(new Object[][]{{false, false}, {false, false}});
    }

@Test
public void TestMethod1(){
assertEquals(expected, Baar.StaticMethod(input);
}

@Test
public void TestMethod2(){
assertEquals(expected, Baar.StaticMethod2(false);
}
@RunWith(参数化的.class)
公开课Foo{
私有布尔输入;
私有布尔期望;
公共Foo(布尔输入,应为布尔值{
这个输入=输入;
这个.预期的=预期的;
}
@参数
公共静态列表数据(){
返回Arrays.asList(新对象[][{{false,false},{false,false});
}
@试验
公共void TestMethod1(){
assertEquals(预期,Baar.StaticMethod(输入);
}
@试验
公共void TestMethod2(){
assertEquals(预期,Baar.StaticMethod2(错误);
}

问题是,当我运行JUnits时,TestMethod1和TestMethod2两个方法都使用这些参数运行。如何告诉testrunner仅运行带有@parameters标记的参数的TestMethod1?

不确定纯junit是否允许,但有大量插件。在您的情况下(所有参数都预先知道)最简单的方法是:


如果您需要在运行时构建参数(生成、读取文件等),那么您可以检查或

之类的内容,不确定纯junit是否允许,但有很多插件。在您的情况下(所有参数都预先知道),最简单的方法是:

如果您需要在运行时构建参数(生成、读取文件等),那么您可以检查或

@RunWith(ZohhakRunner.class)
public class TestMyClass {      

    @TestWith({
        "true, false".
        "false, true"
    })
    public void test1(int actual, int expected) { //test }

    @TestWith({
        "false, false".
        "true, true"
    })
    public void test2(int actual, int expected) { //test }

    @Test
    public void test3() { //test }
}