0
votes

I'd like to run the JUnit tests in our project from the command line using an Ant target. Up until now we ran the tests manually from Eclipse without any issues using the embedded JUnit in Eclipse. After finally having figured out how the set the classpath I now get failed Tests for all classes that use the Parameterized Runner from JUnit 4.11. While running the test target (ant test) the only output is "FAILED" after the name of the Testclass, even with option -v. Generating testreports shows the following Exception:

java.lang.IllegalArgumentException: wrong number of arguments
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)

What does this mean? The version are: - JDK 1.6 - ant 1.9.3 - JUnit 4.11

My build.xml is over 400 lines long so I'm not sure if it makes sense to post it here. Let me know if you need parts of the build.xml.

Update 13.05.2015: Here's a sample section from on of our JUnit Test classes that fail. The @Parameters section contains only one entry which is pretty useless in this case but this class still fails when run from ant.

@Parameters
public static Iterable<String[]> testData() {
return Arrays
    .asList(new String[][] { { "a-rules-filename" } });
}

@Parameter
public String RULES_FILE_NAME;

Our Test class is annotated like this:

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@RunWith(Parameterized.class)
public class OurRulesTest  {
1
Could you please provide the code of you test (@Parameters method and constructor). - Stefan Birkner
Updated the original question with some code. - phivo
OK, it looks as if I have to add a constructor to my test class in order for the Parameterized Runner to work from ant. - phivo

1 Answers

0
votes

The Exception is thrown due to a missing constructor in the test class. It seems that when using the Parameterized Runner you need to specify a constructor with as many arguments as you have parameters. For some reason this works in Eclipse without specifying a constructor.