From: Marius K. <am...@gm...> - 2011-06-25 20:11:56
|
On 25 June 2011 21:19, Marius Kruger <am...@gm...> wrote: > On 20 June 2011 21:57, David Saff <da...@sa...> wrote: > ... >> Parameterized.class currently allows one parameterization per test >> class. This patch enables two parameterizations, one of which must be >> the special case of "no parameters". A runner like JUnitParams >> (http://code.google.com/p/junitparams/) enables an arbitrary number of >> parameterizations, including "no parameters". I'd like to consider >> how to handle the arbitrary case, like JUnitParams, and would rather >> not create a special case for "no parameters" that users would need to >> migrate to the new framework when it's ready. >> >> Does that make sense? > > Yes now that I looked at JUnitParams. It is awesome - much more than I > needed so far. I now found a case that was handled much nicer with my patched version: I just want to setUp(@Before) the tests according to a parameter. This is possible with the standard JUnit Parameterized runner and my version because we get the value in the constructor. eg.: A)== @RunWith(JUnitParamsRunner.class) public class MyJUnitParamsTest { protected AbstractHomeLayout homeLayout; public void setupHomeLayout(int layoutVersion) { homeLayout = init(layoutVersion); } protected Object[] getLayoutVersions() { return new Object[][] { { 0 }, { 1 } }; } @Test @Parameters(method = "getLayoutVersions") public void testParameterized(int layoutVersion) throws IOException { setupHomeLayout(layoutVersion); //test stuff } @Test public void testNonParameterized() throws IOException { //test stuff } // 10 more tests like these } == B)== @RunWith(value = Parameterized.class) public class MyParameterizedTest { int layoutVersion public HomeLayoutTest(int layoutVersion) { this.layoutVersion = layoutVersion; } protected AbstractHomeLayout homeLayout; @Before public void setupHomeLayout() { homeLayout = init(layoutVersion); } @Parameters public static Collection getLayoutVersions() { Object[][] data = new Object[][] { { 0 }, { 1 } }; return Arrays.asList(data); } @Test public void testParameterized() throws IOException { setupHomeLayout(layoutVersion); //test stuff } @Test @NonParameterized public void testNonParameterized() throws IOException { //test stuff } // 10 more tests like these } == So with A you have to modify three lines for every single parameterized test: @Parameters(method = "getLayoutVersions") public void testParameterized(int layoutVersion) throws IOException { setupHomeLayout(layoutVersion); but in B you just annotate the non-parameterized tests... -- <>< Marius ><> |