Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
mlauritse opened this Issue · 0 comments

3 participants

@mlauritse

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, 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:

@RunWith(Parameterized.class)
public class PersistentEntityTest {
private final String entity;

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

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

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

}

@stefanbirkner stefanbirkner referenced this issue from a commit in stefanbirkner/junit
@stefanbirkner stefanbirkner 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
otherwise.
5475e12
@dsaff dsaff closed this in 45eaab7
@marcphilipp marcphilipp referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.