or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

custom-config.mddata-formats.mdindex.mdrunner-annotations.mdutilities.md
tile.json

tessl/maven-com-tngtech-java--junit-dataprovider

A TestNG-like dataprovider runner for JUnit having a simplified syntax compared to all the existing JUnit features.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/com.tngtech.java/junit-dataprovider@1.13.x

To install, run

npx @tessl/cli install tessl/maven-com-tngtech-java--junit-dataprovider@1.13.0

index.mddocs/

JUnit DataProvider

JUnit DataProvider is a Java testing library that extends JUnit 4 with TestNG-style data provider functionality, enabling parameterized tests with enhanced syntax and flexibility. The library provides annotations (@DataProvider, @UseDataProvider) that allow test methods to receive data from various sources including arrays, iterables, and string-based formats, supporting complex test scenarios with multiple data sets.

Package Information

  • Package Name: junit-dataprovider
  • Package Type: maven
  • Language: Java (JDK 1.6+)
  • License: Apache License 2.0
  • Maven Coordinates: com.tngtech.java:junit-dataprovider

Installation

Maven:

<dependency>
    <groupId>com.tngtech.java</groupId>
    <artifactId>junit-dataprovider</artifactId>
    <version>1.13.1</version>
    <scope>test</scope>
</dependency>

Gradle:

testImplementation 'com.tngtech.java:junit-dataprovider:1.13.1'

Core Imports

import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.DataProviderFilter;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import com.tngtech.java.junit.dataprovider.Placeholders;
import org.junit.Test;
import org.junit.runner.RunWith;

Basic Usage

The most common usage pattern involves defining a data provider method and using it in a test:

@RunWith(DataProviderRunner.class)
public class ExampleTest {
    
    @DataProvider
    public static Object[][] stringLengthData() {
        return new Object[][] {
            { "hello", 5 },
            { "world", 5 },
            { "", 0 },
            { "testing", 7 }
        };
    }
    
    @Test
    @UseDataProvider("stringLengthData")
    public void testStringLength(String input, int expectedLength) {
        assertEquals(expectedLength, input.length());
    }
}

Capabilities

Runner and Basic Annotations

The foundation of JUnit DataProvider functionality with the custom runner and core annotations.

@RunWith(DataProviderRunner.class)
public class TestClass {
    
    @DataProvider
    public static Object[][] dataProviderMethod() { /* ... */ }
    
    @Test
    @UseDataProvider("dataProviderMethod")
    public void testMethod(/* parameters */) { /* ... */ }
}

Key APIs:

  • DataProviderRunner - Custom JUnit runner that enables data provider functionality
  • @DataProvider - Annotation for marking data provider methods or providing inline data
  • @UseDataProvider - Annotation for test methods to specify which data provider to use

Runner and Basic Annotations

Data Provider Formats and Types

Support for multiple data formats including arrays, iterables, and string-based data providers.

// Array format
@DataProvider
public static Object[][] arrayData() {
    return new Object[][] { {"test", 4}, {"hello", 5} };
}

// Iterable format  
@DataProvider
public static Iterable<Object[]> iterableData() {
    return Arrays.asList(new Object[]{"test", 4}, new Object[]{"hello", 5});
}

// String format with inline data
@Test
@DataProvider({"test, 4", "hello, 5"})
public void testWithInlineData(String input, int length) { /* ... */ }

Key features:

  • Multiple return type support (Object[][], Iterable variations, String[])
  • Configurable string parsing with custom delimiters
  • Automatic type conversion for primitives, enums, and custom types
  • Null value handling and string trimming options

Data Provider Formats and Types

Utility Methods and Helper Classes

Utility classes and methods for creating and manipulating data provider arrays.

import static com.tngtech.java.junit.dataprovider.DataProviders.*;

// Helper methods for creating data
Object[] row = $("param1", "param2", 123);
Object[][] data = $$($("test1", 1), $("test2", 2));

// Utility methods
Object[][] enumTests = DataProviders.testForEach(MyEnum.class);
Object[][] crossProduct = DataProviders.crossProduct(data1, data2);

Key utilities:

  • DataProviders helper class with $() and $$() methods
  • testForEach() methods for arrays, iterables, and enum classes
  • crossProduct() for combining multiple data providers

Utility Methods and Helper Classes

Custom Resolution and Configuration

Advanced features including custom data provider method resolvers and test name formatting.

// Custom resolver
@UseDataProvider(value = "customName", 
                location = OtherClass.class,
                resolver = CustomDataProviderMethodResolver.class)

// Custom formatting
@DataProvider(format = "%m[%i: %p[0]]")
public static Object[][] formattedData() { /* ... */ }

// Custom placeholders
Placeholders.all().add(0, new CustomPlaceholder());

Key features:

  • DataProviderMethodResolver interface for custom resolution strategies
  • Configurable test method name formatting with placeholder system
  • Support for data providers in external classes
  • Multiple resolution strategies (UNTIL_FIRST_MATCH, AGGREGATE_ALL_MATCHES)

Custom Resolution and Configuration