Java JUnit:类型ParameterizedMethodTest的方法未定义
我的测试要求使用多个数据记录进行测试,而不是一次使用单个记录Java JUnit:类型ParameterizedMethodTest的方法未定义,java,junit,Java,Junit,我的测试要求使用多个数据记录进行测试,而不是一次使用单个记录JUnitParamsRunner适合我的需求,并试图了解它是如何工作的。下面是我的测试课 package test; import static org.junit.Assert.assertEquals; import junitparams.JUnitParamsRunner; import java.util.Arrays; import java.util.Collection; import org.junit.Tes
JUnitParamsRunner
适合我的需求,并试图了解它是如何工作的。下面是我的测试课
package test;
import static org.junit.Assert.assertEquals;
import junitparams.JUnitParamsRunner;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import junitparams.Parameters;
@RunWith(JUnitParamsRunner.class)
public class ParameterizedMethodTest {
@Test
@Parameters(method = "getAddedNumbers")
public void test(int expect,int firstVal,int secondVal) {
assertEquals("ex: "+expect+" act: "+firstVal,expect, multiply(firstVal,secondVal) );
}
public Collection<Integer[]> getAddedNumbers(){
return $( $(1, 1, 1)// compile error under the second $ sign
, $(21, 11, 1)// compile error under the second $ sign
);
}
private int multiply(int a,int b){
return a*b;
}
}
请告诉我此代码哪里出错了?$
是一个错误
所以,为了能够使用它,就像任何静态方法一样,您需要使用
JUnitParamsRunner.$(...);
或者,您需要静态导入该方法,以便能够在不预先添加类名的情况下使用它:
import static junitparams.JUnitParamsRunner.$;
但此方法不返回aInteger[]
或集合
。它返回一个对象[]
。所以您的方法签名必须更改为,正如所示
public Object[] getAddedNumbers()
你为什么认为这个应该编译?
$()
方法在哪里定义?感谢JB的澄清和参考。我可以从中得到很多。。
public Object[] getAddedNumbers()