How to attach a DataPoint with a Theory?

后端 未结 4 966
無奈伤痛
無奈伤痛 2021-02-18 23:59
@DataPoints public static final Integer[] input1={1,2};
@Theory
@Test
public void test1(int input1){

}

@DataPoints public static final Integer[] input2={3,4};
@Theory
         


        
4条回答
  •  余生分开走
    2021-02-19 00:38

    In reference to Gábor Lipták's answer, named datapoints can be defined as a static fields (reference) which give us more concise code:

        @RunWith(Theories.class)
        public class TheoriesAndDataPointsTest {
            @DataPoints("a values")
            public static int[] aValues = {1, 2};
    
            @DataPoints("b values")
            public static int[] bValues = {3, 4};
    
            @Theory
            public void theoryForA(@FromDataPoints("a values") int a) {
                System.out.printf("TheoryForA called with a = %d\n", a);
            }
    
            @Theory
            public void theoryForB(@FromDataPoints("b values") int a) {
                System.out.printf("TheoryForB called with b = %d\n", a);
            }
        }
    

提交回复
热议问题