-
Notifications
You must be signed in to change notification settings - Fork 163
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, ... and you have to provide JUnit.
- since 2.0
- compatible with JUnit4 (JVM 5.0 and above) and JUnit5 (JVM 8 and above)
- since 2.0
-
junit-jupiter-dataprovider
- compatible with JUnit-Jupiter 5.0.0 and above on JVM 8 and above
-
junit-jupiter-params-dataprovider
- compatible with JUnit-Jupiter Parameterized Tests 5.0.0 and above on JVM 8 and above
For concrete JUnit5 versions, see release notes.
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.junit.dataprovider', name: 'junit4-dataprovider', version: '2.6'
// ...
}
pom.xml
:
<dependencies>
<!-- ... -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tngtech.junit.dataprovider</groupId>
<artifactId>junit4-dataprovider</artifactId>
<version>2.6</version>
<scope>test</scope>
</dependency>
<!-- ... -->
</dependencies>
ivy.xml
:
<dependencies>
<!-- ... -->
<dependency org="junit" name="junit" rev="4.12" />
<dependency org="com.tngtech.junit.dataprovider" name="junit4-dataprovider" rev="2.6" />
<!-- ... -->
</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