JUnit Theories: Why can't I use Lists (instead of arrays) as DataPoints?
Posted
by MatrixFrog
on Stack Overflow
See other posts from Stack Overflow
or by MatrixFrog
Published on 2010-06-03T16:30:16Z
Indexed on
2010/06/03
16:34 UTC
Read the original article
Hit count: 150
unit-testing
|junit
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);
Am I doing something wrong, or do List
s really not work? Was it a conscious design choice not to allow the use List
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?
© Stack Overflow or respective owner