尝试运行Junit测试时出现java.lang.IllegalArgumentException错误

3

我正在尝试使用Junit运行一个参数化测试,但是一直出现java.lang.IllegalArgumentException错误。我尝试在谷歌上搜索问题,但似乎无法找到解决方法。如果有任何反馈,将不胜感激。

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个回答

4
public void IsPrimeTest(String numA, boolean expected) {

应该是

public IsPrimeTest(String numA, boolean expected) {

你的构造函数不能有返回类型,否则它就不是构造函数了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接