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]
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿