junit 使用理论进行单元测试
示例
从JavaDoc
Theoriesrunner允许针对一组无限数据点的子集测试某种功能。
运行理论
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
@RunWith(Theories.class)
public class FixturesTest {
@Theory
public void theory(){
//...一些断言
}
}带注释的方法@Theory将被TheoriesRunner视为理论。
@DataPoint批注
@RunWith(Theories.class)
public class FixturesTest {
@DataPoint
public static String dataPoint1 = "str1";
@DataPoint
public static String dataPoint2 = "str2";
@DataPoint
public static int intDataPoint = 2;
@Theory
public void theoryMethod(String dataPoint, int intData){
//...一些断言
}
}每个带有注释的字段@DataPoint将用作理论中给定类型的方法参数。在上面的示例中,theoryMethod将使用以下参数运行两次:["str1",2],["str2",2]
@DataPoints批注@RunWith(Theories.class)公共类FixturesTest{
@DataPoints
public static String[] dataPoints = new String[]{"str1", "str2"};
@DataPoints
public static int[] dataPoints = new int[]{1, 2};
@Theory
public void theoryMethod(String dataPoint, ){
//...一些断言
}
}带有@DataPoints注释的数组中的每个元素都将用作理论中给定类型的方法参数。在上面的示例中,theoryMethod将使用以下参数运行四次:["str1",1],["str2",1],["str1",2],["str2",2]
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短