1

In the following code, I would like to run TestMethod1 with the parameters marked with @Parameters

    @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);
}

The Problem is when I run junittes, both methods TestMethod1 and TestMethod2 are run with these parameters. How to tell the testrunner to run only TestMethod1 with the parameters marked with @Parameters?

piotrek
  • 13,982
  • 13
  • 79
  • 165
Ronald
  • 2,721
  • 8
  • 33
  • 44

1 Answers1

0

not sure if pure junit allows it but there is plenty of plugins. in your case (all parameters known up-front) the simplest way would be to do parametrized testing with zohhak:

@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 }
}

if you need to build parameters in run-time (generating, reading from file etc.) then you can check things like junit-dataprovider or junit-params

piotrek
  • 13,982
  • 13
  • 79
  • 165