Reputation: 109
I am trying to run a parameterized test with Junit but I keep getting the error java.lang.IllegalArgumentException. I have tried google the problem but I just cannot seem to figure it out exactly why this code is not working. Any feedback would be greatly appreciated.
package mainPackage;
import static org.junit.Assert.*;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collection;
import org.hamcrest.Matcher;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(value = Parameterized.class)
public class IsPrimeTest {
private String numA;
private boolean expected;
public void IsPrimeTest(String numA, boolean expected) {
this.numA = numA;
this.expected = expected;
}
@Parameters
public static Collection<Object[]> data(){
return Arrays.asList(new Object[][]{
{"13", true}
});
}
@Test
public void ParameterizedTestIsPrime() {
IsPrime test = new IsPrime();
assertEquals(IsPrime.isPrime(new BigInteger(numA)), expected);
}
}
Upvotes: 4
Views: 2267
Reputation: 4647
public void IsPrimeTest(String numA, boolean expected) {
should be
public IsPrimeTest(String numA, boolean expected) {
Your constructor can't have a return type, else it's not a constructor.
Upvotes: 4