我正在創建基於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