2013-03-04 21 views
12

ben parametreli testler oluşturmak için JUnit 4 kullanın JRE 6. dayanan bir Java uygulaması oluşturma. Ek açıklama içeren satırdaJava JUnit Parameterized hatası

The annotation @Parameterized.Parameters must define the attribute value

: Ben bu hatayı alıyorum ben başardı

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

: Aşağıda

@Parameterized.Parameters 

bu konuyla ilgili olduğuna inandığımız koddur this gibi bazı ilgili soruları bulabilirsiniz. Ne yazık ki, benim durumumda hiçbir yardımı yok.

denedim ve işe yaramadı Ne: Sınıf bildirimi

  • @Test notu kullanın ekleyerek test fonksiyonları gelen "BasicCalculatorTest uzanır" çıkarmadan

    • org.junit.runners.Parameterized ithal ve @Parameters yerine @ Parameterized.Parameters kullanılarak

    Başka bir projede herhangi bir sorun yaşamadan çok benzer bir uygulama kullandığımı (özellikle notları ve testGenerator()) kullandığımı belirtmem gerekir. uygulama böyle this, this ve this olarak online eğitimlerimizi takip eder.

    bu hatayı çözme üzerinde herhangi bir Yardım büyük takdir edilmektedir.

  • +2

    '@ Parameterized.Parameters (value =/* required here * /)' error, "value" özniteliğinin zorunlu olduğunu belirtir. –

    +0

    @PaulBellora, sadece bir yazım hatası oldu, o işaret için teşekkürler, bu sorunu giderdim ama sorun hala devam etmektedir. –

    +0

    @BheshGurung, bunu söylediğini biliyorum ama bunu başka bir projede kullanmadan kullandım (value =/* burada */gerekir) ve iyi çalıştı. Ayrıca, bağladığım eğiticilerin hiçbiri bunu kullanmıyor. –

    cevap

    1

    bu deneyin:

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

    çıkışı:

    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

    Sorun, bu kodda da oluşur. –

    +0

    Bu benim jdk7 kullanarak benim için iyi çalışır ve 7 x64 –

    +0

    üzerinde tutulması temel test durumu uzatmayı unuttum. Bunu düzenledim ve çıktıyı ekledim. –

    0

    Eğer BaseTestCase uzatmak çünkü olmalı. Testinizi doğru bir taban sınıfından genişletmeden kodunuzu kopyaladım. Kurulumunuzla

    Ör içinde super.setUp() çağırarak

    deneyin

    @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

    Aşağıdakileri kaçırdığımı düşünüyorum.

    import org.junit.runners.Parameterized.Parameters;