2

I wish to run a single JUnit test from the command line. I've tried the solution suggested in: Run single test from a JUnit class using command-line

It does seem to work for regular tests, but seems to fail in running Parameterized tests.

Here is my test:

@RunWith(Parameterized.class)
public class ParameterizedTests {
    private final int param;

    public ParameterizedTests(int param) {
        this.param = param;
    }

    @Parameters
    public static Collection<Object[]> generateData() {     
        List<Object[]> data = new ArrayList<Object[]>();

        data.add(new Object[]{1});
        data.add(new Object[]{5});
        data.add(new Object[]{20});

        return data;
    }

    @Test
    public void test() {
        fail("Not yet implemented:" + param);
    }
}

Running the suggested solution on the provided test gave the following error:

There was 1 failure: 1) initializationError(org.junit.runner.manipulation.Filter) java.lang.Exception: No tests found matching Method test(aaa.ParameterizedTests) from org.junit.internal.requests.ClassRequest@ 61145cc at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:35) at org.junit.runner.JUnitCore.run(JUnitCore.java:138) at aaa.singletestrunner.SingleTestRunner.main(SingleTestRunner.java:17)

FAILURES!!! Tests run: 1, Failures: 1

I wish to run all variants of the test method (of course in real code there are multiple tests in this class and I wish to execute only a single test from this class)

Can anyone provide a solution?

Community
  • 1
  • 1
AntonKam
  • 163
  • 11

0 Answers0