Usage

Setting up Maven

The following pom.xml creates a simple project. Beside the dependency you need also to specify an additional repository from where Maven can get the jar's.

<?xml version="1.0" encoding="UTF-8"?>
<project>

	<modelVersion>4.0.0</modelVersion>
	<groupId>com.seitenbau.testing</groupId>
	<artifactId>sb-tutorial-parameterzied</artifactId>
	<version>1.0-SNAPSHOT</version>
	<name>An JUnit Parameterized Test example</name>

	<repositories>
		<repository>
			<id>JUnitRecorder-repositry</id>
			<name>JUnitRecorder repositry</name>
			<url>http://junitrecorder.sourceforge.net/m2</url>
		</repository>
	</repositories>
	
	<dependencies>
		<dependency>
			<groupId>com.seitenbau.testing</groupId>
			<artifactId>junit-parameterized-test</artifactId>
			<version>1.0.0</version>
		</dependency>

	</dependencies>
	
</project>

Run "mvn eclipse:eclipse" and you can import the project into eclipse.

Test class

First let us create a minimal Class to run a parameterized Test.

@RunWith( ParameterizedTestRunner.class )
public class ATestClass {
	
	@ParameterizedTest
	@XmlDataOption(file="ATestClass-testMethod.xml")
	public void testMethod( int value1, int value2 ) {
		System.out.println("Values [" + value1 +"] ["+ value2 + "]");
	}
}

As you can see the execution is done with a normal JUnit TestRunner, therefore the Integration in all JUnit aware environments is easily possible.

Beside the Test Runner the actual Test Method is marked with the "@DataDrivenTest" Annotation and the XML data file is passed by the "@XmlDataOption" Annotation. Btw: the JUnit "@Test" and "@Ignore" Annotations are still working.

Test data

Now lets take a look at a simple XML data file:

<testfile>
	<tests>
		<test id="1" name="This is the first Dataset">
			<parameters>
				<int>12</int>
				<int>32</int>
			</parameters>
		</test>
		<test id="2" name="This is the second Dataset">
			<parameters>
				<int>42</int>
				<int>99</int>
			</parameters>
		</test>
	</tests>
</testfile>

Run the test

As already mentioned because a TestRunner is used, you can use your normal tool. E.g. Eclipse:

When you run with Maven:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.example.ATestClass
Values [12] [32]
Values [44] [99]
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.08 sec

Results :

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0