-
Notifications
You must be signed in to change notification settings - Fork 164
Getting started
TODO provide features of JUnit5 (see Migration guides for now). Sorry for the inconvenience.
The junit-dataprovider requires a JVM-compatible development environment, such as Java, Groovy, Scala, ...
Furthermore, you have to provide JUnit in version 4.8.2+ as dependency (see junit-dep-4.8.2 / junit-4.8.2). If you are using a previous version and cannot upgrade, please let us know by opening an issue here.
All released (= tagged) versions are available at Maven Central Repository. Following this link you can choose a version. For more information about a certain version, see release notes. Now either download it manually or see the Dependency Information section how to integrate it with your dependency management tool or use one of the following excerpts for the most populare Java build tools:
Note: The following example excerpts use JUnit in version 4.12
and junit-dataprovider in version 1.10.0
. Please change this according to your preferences:
build.gradle
:
repositories {
mavenCentral()
}
dependencies {
// ...
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'com.tngtech.java', name: 'junit-dataprovider', version: '1.10.0'
// ...
}
pom.xml
:
<dependencies>
<!-- ... -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tngtech.java</groupId>
<artifactId>junit-dataprovider</artifactId>
<version>1.10.0</version>
<scope>test</scope>
</dependency>
<!-- ... -->
</dependencies>
ivy.xml
:
<dependencies>
<!-- ... -->
<dependency org="junit" name="junit" rev="4.12" />
<dependency org="com.tngtech.java" name="junit-dataprovider" rev="1.10.0" />
<!-- ... -->
</dependencies>
After including one of the above excerpts in your build file and refreshing your IDE, you simple can create a new JUnit test and use the junit-dataprovider:
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
@RunWith(DataProviderRunner.class)
public class DataProviderTest {
@DataProvider
public static Object[][] dataProviderAdd() {
// @formatter:off
return new Object[][] {
{ 0, 0, 0 },
{ 1, 1, 2 },
/* ... */
};
// @formatter:on
}
@Test
@UseDataProvider("dataProviderAdd")
public void testAdd(int a, int b, int expected) {
// Given:
// When:
int result = a + b;
// Then:
assertEquals(expected, result);
}
}
For more features and customization possibilities, see Features.
- Home
- Motivation, Distinction and FAQs
- Getting started
- Version compatibility
- Migration guides
-
Features
- Array syntax
- String syntax
- Iterable syntax
- Custom dataprovider method resolvers
- Change
@DataProvider
location - Varargs support
@BeforeClass
support (JUnit4 only)- Customize test method name
- Access
FrameworkMethod
in@DP
- Utility methods
- Convention over configuration
- Kotlin support
- OSGi compatible
MANIFEST.MF
- Tips and Tricks
- Release Notes
- Eclipse Template