An issue is raised when two or more methods that provide test data use the same identifier value within the same test class scope.

In Java with TestNG, this specifically refers to methods annotated with @DataProvider using the same name attribute value.

Why is this an issue?

Test framework data provider mechanisms allow you to define methods that supply test data to your test methods. Each data provider is identified by its name attribute, which test methods reference using configuration parameters in their test annotations.

When multiple data provider methods share the same name within a class, the test framework faces ambiguity about which data provider to use. The framework’s behavior in this situation is undefined and implementation-dependent. It may:

This ambiguity makes your tests unreliable and unpredictable. A test that passes today might fail tomorrow, or vice versa, without any changes to the actual code being tested. This undermines the entire purpose of automated testing.

Additionally, duplicate names make it difficult for developers to understand which data is being used for which tests, reducing code maintainability and making debugging more challenging.

In TestNG specifically, this refers to the @DataProvider annotation with its name attribute, which test methods reference using the dataProvider parameter in the @Test annotation.

What is the potential impact?

When test data source identifiers are duplicated, test execution becomes unpredictable. Tests may:

This unreliability can lead to:

How to fix it

Ensure each @DataProvider method in a class has a unique name attribute. Choose descriptive names that clearly indicate what data each provider supplies.

Code examples

Noncompliant code example

@DataProvider(name = "testData")
public Object[][] provider1() {
    return new Object[][] {
        {"value1", 1},
        {"value2", 2}
    };
}

@DataProvider(name = "testData") // Noncompliant
public Object[][] provider2() {
    return new Object[][] {
        {"value3", 3},
        {"value4", 4}
    };
}

Compliant solution

@DataProvider(name = "testData")
public Object[][] provider1() {
    return new Object[][] {
        {"value1", 1},
        {"value2", 2}
    };
}

@DataProvider(name = "additionalTestData")
public Object[][] provider2() {
    return new Object[][] {
        {"value3", 3},
        {"value4", 4}
    };
}

Resources

Documentation