2017-06-29 132 views
3

我想用Junit運行參數化測試,但我不斷收到錯誤java.lang.IllegalArgumentException。我曾試圖谷歌的問題,但我似乎無法弄清楚爲什麼這段代碼不工作。任何反饋將不勝感激。嘗試運行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); 
    } 
} 

回答

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

應該

public IsPrimeTest(String numA, boolean expected) { 

構造函數不能有返回類型,否則它不是一個構造函數。

相關問題