No, there is no functionality like โtest case inside test caseโ, except for loops!
Cycles to the rescue!
@Test public void xmlShouldBeValid() { String[] templates = new String[]{ TEMPLATE1, TEMPLATE2, TEMPLATE3 }; for (String template : templates) { testTemplate(template); } } private void testTemplate(String template) { assertEquals("whatever", template); }
Something like this might help. Another trick I use is to make helper methods assert *. So if I check that XML has 3 attributes a, b and c, I can write
private void assertTemplate(String template, String a, String b, int c) { String aFromTemplate = parseAfromTemplate(template);
Now you can call assertTemplate several times in one test function:
@Test public void xmlShouldBeValid() { assertTemplate("<hardcoded xml object>", "a", "b", "c"); assertTemplate("<hardcoded xml object>", "r", "s", "t"); assertTemplate("<hardcoded xml object>", "x", "y", "z"); }
Of course, instead of using String for the template type, replace the XML object with any framework (if any) that you are using.
source share