This JUnit Parameterized Test project provides a JUnit 4.4 Test Runner which implements the Parameterized Test pattern .
As already stated this project was developed for the JUnitRecorder project. It was necessary to overcome some shortcomings of the JUnit ParameterizedTestRunner which is directly provided by JUnit.
Let's take a look at a plain JUnit test i with a ParameterizedTestRunner:
@RunWith(Parameterized.class)
public class XStreamControlCharTest
{
private XStream myXStream;
private String myOrginalString;
private String myExpectedXml;
@Before
public void before() {
myXStream = new XStream(new HideControlCharXppDriver());
}
public XStreamControlCharTest(String orginalString, String expectedXML)
{
myOrginalString = orginalString;
myExpectedXml = expectedXML;
}
@Parameters
public static Collection getMocks() {
return Arrays.asList(new Object[][] {
/* 0 */{"HelloWorld", "<string>HelloWorld</string>"}
/* 1 */, {"Hello World", "<string>Hello World</string>"}
[...]
/* 21 */, {"\\{0}", "<string>\\\\{0}</string>"}});
}
@Test
public void runTest() {
String xml = myXStream.toXML(myOrginalString);
// Serialization Test
assertEquals(myExpectedXml, xml);
String neu = (String) myXStream.fromXML(xml);
// deserialization Test
assertEquals(myOrginalString, neu);
}
}
To overcome this shortcomings the JUnit Parameterized Test module was created:
How this is really achieved you should continue reading the Usage .