Is it possible to group DataPoints by something other than their type?
For example, suppose I have a Theory that I want to test, using "age" and "weight" as parameters:
@Theory
public void testSomething(int age, int weight) { ... }
where, say, "age" could be 10, 20, or 50, and weight could be 50, 100, or 200.
AFAIK, I can't tell JUnit that some of the int DataPoints correspond to ages, and 开发者_运维百科other ones correspond to weights. Does anybody know if there's a way to do this?
I believe that data points are static, so I don't think you'll be able to use them here.
FYI, here is how you would do this with TestNG:
@DataProvider
public Object[][] dp() {
List<Object[]> result = Lists.newArrayList();
for (int i : Arrays.asList(10, 20, 50)) {
for (int j : Arrays.asList(50, 100, 200)) {
result.add(new Object[] { i, j });
}
}
return result.toArray(new Object[result.size()][]);
}
@Test(dataProvider = "dp")
public void testSomething(int age, int weight) {
System.out.println("Age:" + age + " weight:" + weight);
}
will print:
Age:10 weight:50
Age:10 weight:100
Age:10 weight:200
Age:20 weight:50
Age:20 weight:100
Age:20 weight:200
Age:50 weight:50
Age:50 weight:100
Age:50 weight:200
===============================================
SingleSuite
Total tests run: 9, Failures: 0, Skips: 0
===============================================
精彩评论