我已经开始使用新的(ish)JUnit Theories用于参数化测试的功能。例如,如果您的理论设置为采用 Integer
参数,Theories
测试运行程序拿起任何 Integer
s 标有 @DataPoint
:
@DataPoint
public static Integer number = 0;
以及任何
Integer
s 在数组中:@DataPoints
public static Integer[] numbers = {1, 2, 3};
甚至返回数组的方法,如:
@DataPoints
public static Integer[] moreNumbers() { return new Integer[] {4, 5, 6}; };
但不在
List
s。以下不起作用:@DataPoints
public static List<Integer> numberList = Arrays.asList(7, 8, 9);
编辑 :看起来也不支持其他集合,因为这不起作用。
@DataPoints
public static Collection<Integer> numberList = new HashSet<Integer>() {{
add(7);
add(8);
add(9);
}};
我做错了什么,还是做
List
s, Set
s等真的不行吗?不允许使用 Collection
是否是有意识的设计选择? s 作为数据点,还是只是尚未实现的功能?是否有计划在 future 版本的 JUnit 中实现它?(我目前使用的是 4.8.1 版本,而最新版本是 4.8.2 但 it looks like 这不是 4.8.2 中添加的内容)
最佳答案
我已经查看了这个问题,现在似乎有一个待处理的提交。它不在那里的原因似乎只是没有人要求它,而且做起来很复杂(正如您在 your patch 中所证明的那样)
关于unit-testing - JUnit 理论 : Why can't I use Lists (instead of arrays) as DataPoints?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2967912/