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]
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短