本文介绍了Allure TestNG:使用@DataProvider 时的自定义测试方法名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 java testng 测试中使用 allure-testng(2.12.1) 适配器.我有使用@DataProvider 的测试.我的测试实现 ITest 以在运行时更改测试方法实例名称.当我运行测试时,我看到不同的测试方法名称,但在 allure-report 中,它为每次测试运行显示相同的测试方法.如何配置诱惑报告以显示类似于 IDE?
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
推荐答案
尝试使用
AllureLifecycle lifecycle = Allure.getLifecycle();
//change test name to "CHANGED_NAME"
lifecycle.updateTestCase(testResult -> testResult.setName("CHANGED_NAME"));
这篇关于Allure TestNG:使用@DataProvider 时的自定义测试方法名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!