|
From: David S. <da...@sa...> - 2011-06-27 15:40:17
|
Good point. Here's how I'm thinking about moving forward: we currently have @Rule, which provides a way to override the rules for _running_ a method, for _every @Test_ method in the class. I'm considering a similar construct, which will allow overriding: 1) Which methods trigger tests 2) How many tests per method 3) Validation of test methods 4) Test-instance creation 5) Test-method invoking Given this, it should be possible to enable something very close to @NonParameterized as a drop-in Rule-like object, rather than as a core modification to the overall Parameterized runner. One issue: I can't think of a name for this new construct. Suggestions welcome. David Saff On Sat, Jun 25, 2011 at 4:11 PM, Marius Kruger <am...@gm...> wrote: > 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 ><> > |