2013-03-04 3 views
12

JRE 6을 기반으로 Java 응용 프로그램을 작성하고 있습니다. JUnit 4를 사용하여 매개 변수화 된 테스트를 생성합니다. 주석이 포함 된 줄에Java JUnit 매개 변수화 된 오류

The annotation @Parameterized.Parameters must define the attribute value

: :이 오류가 발생하고 I가 관리

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} 
     }); 
    } 

: 아래

@Parameterized.Parameters 

을 나는이 문제와 관련된 생각하는 코드입니다 this과 같이 멀리 관련 질문을 찾아보십시오. 슬프게도, 제 상황에서는 도움이 안됩니다.

나는 시도하고 작동하지 않았다 일 :이 클래스 선언

  • @Test 주석을 사용하는 추가 테스트 기능에서 "BasicCalculatorTest를 확장"제거

    • org.junit.runners.Parameterized를 가져오고 @ Parameterized.Parameters 대신 @Parameters를 사용합니다.

    필자는 다른 프로젝트에서 아주 비슷한 구현 (특히 주석과 testGenerator())을 아무 문제없이 사용했다는 것을 언급해야합니다. 구현은 this, thisthis과 같이 온라인에서 사용할 수있는 자습서를 따릅니다.

    이 오류를 해결하는 방법에 대한 도움을 주시면 감사하겠습니다.

  • +2

    '@ Parameterized.Parameters (value =/* required here * /)'오류는 'value'속성은 필수 항목입니다. –

    +0

    @PaulBellora, 그냥 오타였습니다. 지적 해 주셔서 감사합니다. 문제를 해결했지만 문제는 여전히 남아 있습니다. –

    +0

    @ BheshGurung, 나는 그것을 말하고 있지만 다른 프로젝트에서는 (value =/* 여기에 * 필요함) 사용했지만 제대로 작동했습니다. 또한, 내가 사용하는 튜토리얼은 이것을 사용하지 않습니다. –

    답변

    1

    이 시도 :

    import java.util.Arrays; 
    import java.util.Collection; 
    
    import org.junit.Test; 
    import org.junit.runner.RunWith; 
    import org.junit.runners.Parameterized; 
    import org.junit.runners.Parameterized.Parameters; 
    public class So15213068 { 
        public static class BaseTestCase { 
         @Test public void test() { 
          System.out.println("base class test"); 
         } 
        } 
        @RunWith(Parameterized.class) public static class TestCase extends BaseTestCase { 
         public TestCase(Double nr1,Double nr2) { 
          //super(nr1,nr2); 
          this.nr1=nr1; 
          this.nr2=nr2; 
         } 
         @Test public void test2() { 
          System.out.println("subclass test "+nr1+" "+nr2); 
         } 
         @Parameters public static Collection<Object[]> testGenerator() { 
          return Arrays.asList(new Object[][]{{-100.,-100.},{-100.,100.},{100.,-100.},{100.,100.}}); 
         } 
         double nr1,nr2; 
        } 
    } 
    

    출력 :

    subclass test -100.0 -100.0 
    base class test 
    subclass test -100.0 100.0 
    base class test 
    subclass test 100.0 -100.0 
    base class test 
    subclass test 100.0 100.0 
    base class test 
    
    +0

    이 코드에서도 문제가 발생합니다. –

    +0

    이것은 jdk7과 이클립스 7 x64를 사용하여 나를 위해 잘 실행됩니다 –

    +0

    기본 테스트 케이스를 확장하는 것을 잊어 버렸습니다. 나는 그것을 편집하고 결과물을 추가했다. –

    0

    당신이 BaseTestCase을 확장하기 때문에이 있어야합니다. 테스트가 올바르게 실행되는 기본 클래스에서 확장하지 않고 코드를 복사했습니다. 셋업

    일예에 super.setUp()를 호출

    시도

    @Before 
    @Override 
    public void setUp() throws Exception { 
        super.setUp(); 
        sciCalc = new ScientificCalculator(); 
        //Make sure that the basic functionality of the extended calculator 
        //hasn't been broken. 
        theCalc = sciCalc; 
    } 
    
    1

    나는 아래의 수입을 놓친다 고 생각합니다.

    import org.junit.runners.Parameterized.Parameters; 
    
    관련 문제