我正在创建基于JRE 6的Java应用程序。我使用JUnit 4生成参数化测试。我收到此错误:在包含注释行Java JUnit参数化错误
The annotation @Parameterized.Parameters must define the attribute value
:
@Parameterized.Parameters
下面是我认为是与这一问题有关的代码:
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import calc.CalculatorException;
import calc.ScientificCalculator;
@RunWith(Parameterized.class)
public class ScientificCalculatorTest extends BasicCalculatorTest{
/** Provides an interface to the scientific features of the calculator under test */
private ScientificCalculator sciCalc;
private double a, b;
@Before
@Override
public void setUp() throws Exception {
sciCalc = new ScientificCalculator();
//Make sure that the basic functionality of the extended calculator
//hasn't been broken.
theCalc = sciCalc;
}
/**
* Constructor. Is executed on each test and sets the test values to each pair in the data sets.
* @param nr1 the first number in the tested pair.
* @param nr2 the second number in the tested pair.
*/
public ScientificCalculatorTest(double nr1, double nr2){
a = nr1;
b = nr2;
}
@Parameterized.Parameters
public static Collection<Object[]> testGenerator() {
return Arrays.asList(new Object[][] {
//General integer values | -/+ combinations
{ -100, -100},
{ -100, 100},
{ 100, -100},
{ 100, 100}
});
}
我设法找到一些与此相关的问题,如this。可悲的是,在我的情况下,他们没有任何帮助。
我曾尝试和没有工作:
取出从类声明
使用@Test标注添加测试功能 “延伸BasicCalculatorTest”
导入org.junit.runners.Parameterized并使用@Parameters代替@ Parameterized.Parameters
我需要提到的是,我在另一个项目中使用了一个非常类似的实现(最值得注意的是annotations和testGenerator()),没有任何问题。实施遵循在线提供的教程,如this,this和this。
任何帮助解决这个错误是非常感谢。
'@ Parameterized.Parameters(value =/* here here * /)'该错误说明属性'value'是强制性的。 – 2013-03-04 23:31:06
@PaulBellora,这只是一个错字,感谢您指出它,我已经纠正它,但问题仍然存在。 – 2013-03-04 23:32:27
@BheshGurung,我知道它说,但我已经在另一个项目中使用它(value =/*这里需要* /),它工作得很好。另外,我没有链接的教程使用这个。 – 2013-03-04 23:34:13