问题
I am using allure-testng(2.12.1) adapter in my java testng tests. I have tests that are using @DataProvider. My test implements ITest to change the test method instance name during runtime. When I run the tests, I see the different test method names, but in allure-report it shows same test method for each test run. How can I configure allure report to show similar to IDE?
@Listeners({AllureTestNg.class, EmailableReporter.class})
public class AllureTests implements ITest {
private ThreadLocal<String> testName = new ThreadLocal<>();
@Override
public String getTestName() {
return testName.get();
}
@BeforeMethod(alwaysRun = true)
public void BeforeMethod(Method method, Object[] testData){
testName.set(testData[0].toString());
}
@Test (dataProvider = "testData")
@Description("Hi")
public void myTest(String value){
Assert.assertNotNull(value);
System.out.println(String.format("Test Instance Name: %s", Reporter.getCurrentTestResult().getTestName()));
}
@DataProvider(name = "testData")
public Iterator<Object[]> getTestAPICases() {
List<Object[]> testList=new ArrayList<Object[]>();
testList.add(new Object[]{"testOne"});
testList.add(new Object[]{"testTwo"});
testList.add(new Object[]{"testThree"});
return testList.iterator();
}
}
Expected: testOne testTwo testThree
Actual: myTest myTest myTest
回答1:
try to use
AllureLifecycle lifecycle = Allure.getLifecycle();
//change test name to "CHANGED_NAME"
lifecycle.updateTestCase(testResult -> testResult.setName("CHANGED_NAME"));
回答2:
You can change the test case name at runtime by writing below code in @Test method :
@Test
public void test1()
{
AllureLifecycle lifecycle = Allure.getLifecycle();
lifecycle.updateTestCase(testResult -> testResult.setName("CHANGED_NAME"));
log.ifo("Changing test case name");
}
来源:https://stackoverflow.com/questions/56550444/allure-testng-custom-test-method-names-while-using-dataprovider