4

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

1 Answer 1

4
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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.