Junit系列之四
2019獨角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
@Parameters---用于多個測試用例,方便的應(yīng)用各測試用例.
用于構(gòu)造器
@RunWith(value = Parameterized.class) public class ParameterizedTest {private int numberA;private int numberB;private int sum;public ParameterizedTest(int numberA, int numberB, int sum) {this.numberA = numberA;this.numberB = numberB;this.sum = sum;}public static final Object[][] math = new Object[][]{{1, 1, 2},{2, -4, -2},{3, 3, 6},{3, 7, 10}};@Parameterspublic static Iterable<Object[]> getNumber() {return Arrays.asList(math);}@Testpublic void test() {Assert.assertThat((numberA + numberB) == sum, is(true));} }這里Iterable<T>或者用Collection<T>范型最好里面用Object數(shù)組或者Object,即使它是整數(shù).
用于Field
@RunWith(value = Parameterized.class) public class ParameterizedTest {@Parameter(value = 0)public int numberA;@Parameter(value = 1)public int numberB;@Parameter(value = 2)public int sum;public static final Object[][] math = new Object[][]{{1, 1, 2},{2, -4, -2},{3, 3, 6},{3, 7, 10}};@Parameterspublic static Iterable<Object[]> getNumber() {return Arrays.asList(math);}@Testpublic void test() {Assert.assertThat((numberA + numberB) == sum, is(true));} }轉(zhuǎn)載于:https://my.oschina.net/xd03122049/blog/1217780
總結(jié)
- 上一篇: React 状态管理库: Mobx
- 下一篇: Exchange 2013之(三)CAS