我已经开始使用新的 JUnit 理论 用于参数化测试的功能。例如,如果您的理论设置为采用 Integer
参数,则 Theories
测试运行程序会选取任何标有 Integer
的>@DataPoint:
@DataPoint
public static Integer number = 0;
以及数组中的任何Integer
:
@DataPoints
public static Integer[] numbers = {1, 2, 3};
甚至是返回数组的方法,例如:
@DataPoints
public static Integer[] moreNumbers() { return new Integer[] {4, 5, 6}; };
但不在List
中。以下不起作用:
@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
、Set
等确实不起作用?不允许使用集合作为数据点是一个有意识的设计选择,还是这只是一个尚未实现的功能?是否有计划在 JUnit 的未来版本中实现它?
(我目前使用的是版本 4.8.1,而最新版本是 4.8.2,但是 看起来这不是4.8.2中添加的东西)
I've started using the new(ish) JUnit Theories feature for parameterizing tests. If your Theory is set up to take, for example, an Integer
argument, the Theories
test runner picks up any Integer
s marked with @DataPoint
:
@DataPoint
public static Integer number = 0;
as well as any Integer
s in arrays:
@DataPoints
public static Integer[] numbers = {1, 2, 3};
or even methods that return arrays like:
@DataPoints
public static Integer[] moreNumbers() { return new Integer[] {4, 5, 6}; };
but not in List
s. The following does not work:
@DataPoints
public static List<Integer> numberList = Arrays.asList(7, 8, 9);
Edit: It looks like other collections are not supported either, as this does not work.
@DataPoints
public static Collection<Integer> numberList = new HashSet<Integer>() {{
add(7);
add(8);
add(9);
}};
Am I doing something wrong, or do List
s, Set
s, etc. really not work? Was it a conscious design choice not to allow the use of Collection
s as data points, or is that just a feature that hasn't been implemented yet? Are there plans to implement it in a future version of JUnit?
(I'm currently using version 4.8.1 whereas the newest version is 4.8.2 but it looks like this is not something that was added in 4.8.2)
发布评论
评论(1)
我已经查看了这个问题,似乎现在有一个待提交的提交。它不在那里的原因似乎很简单,没有人要求它,而且做起来相当复杂(正如您在 你的补丁)
I've looked at the issue, and it seems there is now a pending commit for it. The reason that it wasn't in there seems to be simply that nobody asked for it and it's quite complex to do (as you've proven in your patch)