testng
testng copied to clipboard
can not set custom test method name when using data provider
TestNG Version
7.10.2
Expected behavior
I should be able use a value from data provider and use it as a custom test name
Actual behavior
The Test method name appears in emailable report but not the custom name
Is the issue reproducible on runner?
Yes
- [ ] Shell
- [x] Maven
- [ ] Gradle
- [ ] Ant
- [ ] Eclipse
- [x] IntelliJ
- [ ] NetBeans
Test case sample
package com.example.tests;
import org.testng.ITest;
import org.testng.ITestResult;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.reflect.Method;
public class MyTest2 implements ITest {
private String name;
@BeforeMethod(description = "Set test case name", alwaysRun = true)
public void beforeMethod(Method method, ITestResult result, Object[] data) {
name = (String) data[0];
}
@DataProvider(name = "data-provider")
public Object[][] dpMethod() {
return new Object[][]{
{"NYC"},
{"Chicago"}
};
}
@Test(dataProvider = "data-provider")
public void myTest(String city) {
System.out.println("city = " + city);
}
@Override
public String getTestName() {
return name;
}
}
Emailable report:
Contribution guidelines
Incase you plan to raise a pull request to fix this issue, please make sure you refer our Contributing section for detailed set of steps.