Parameterized: data() returns Collection<Object[]>, which in Parameterized.getParametersList() is cast to List<Object[]> #104

mlauritse opened this Issue May 17, 2010 · 0 comments


None yet
3 participants

First of all, I was very happy to discover the Parameterized runner today, I came very close to reverting to a JUnit 3 Suite, but stumbled on this very elegant solution to a common enough problem - dynamically configuring a bunch of tests whose results should be reported separately.

@parameters data() returns Collection<Object[]>, but in Parameterized.getParametersList(), this collection is immediately cast to List. This is unfortunate if the Collection is not a List.

A simple workaround is to simply return a list from data(), but really, I think this is unnecessarily confusing, and I don't see any reason why Parameterized would care what kind of Collection this is.

Here's an example which demonstrates the issue:

public class PersistentEntityTest {
private final String entity;

public PersistentEntityTest(String entity) {
    this.entity = entity;

public void test() {
    Assert.assertEquals("testEntity", this.entity);

public static Collection<Object[]> data() {
    return Collections.singleton(new Object[] { "testEntity" });


stefanbirkner added a commit to stefanbirkner/junit that referenced this issue Oct 20, 2011

Use Iterable for the parameters of Parameterized (fixes #104).
The method annotated with @Parameterized returns an Iterable<Object[]>
(was List<Object[]> before). The test fails with a meaningful exception

@dsaff dsaff closed this in 45eaab7 Dec 31, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment