Open GoogleCodeExporter opened 8 years ago
Original comment by lipinski...@gmail.com
on 26 Oct 2013 at 3:56
For those finding this page via Google, including objects that can't be parsed
from a CSV string in the arguments passed to a test can be accomplished as
shown in the following snippet:
private static final Object DEFAULT_VALUE = new String("It works!");
private static final Object OTHER_VALUE = new String("It's broken!");
private Object foo(String input) {
Object output = DEFAULT_VALUE;
if(input != null && !"".equals(input.trim())) {
output = OTHER_VALUE;
}
return output;
}
@SuppressWarnings("unused")
private Object[] parameters() {
return $(
new Object[] { null },
new Object[] { "" },
new Object[] { " " }
// ,"Other value"
);
}
@Test
@Parameters(method = "parameters")
public void testing(String input) {
Object obj = foo(input);
assertEquals(obj, DEFAULT_VALUE);
}
This code was posted as an answer to a question on StackOverflow
(http://stackoverflow.com/questions/20389114/junit-same-testcase-with-different-
inputs) and can be used as the basis for the suggested wiki page, since my
experience is that sending null and empty Strings is the most common
problematic case.
Original comment by smoye...@gmail.com
on 5 Dec 2013 at 2:57
Original issue reported on code.google.com by
smoye...@gmail.com
on 13 Sep 2013 at 3:25