我在java testng测试中使用了allure-testng(2.12.1)适配器。我有使用@DataProvider的测试。我的测试实现了ITest以在运行时更改测试方法实例名称。运行测试时,我看到了不同的测试方法名称,但是在“魅力报告”中,它为每次测试运行显示了相同的测试方法。如何配置魅力报告以显示类似于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();
}
}
预期: testOne 测试二 testThree
实际: myTest myTest myTest
答案 0 :(得分:1)
您可以在运行时通过在@Test方法中编写以下代码来更改测试用例名称:
@Test
public void test1()
{
AllureLifecycle lifecycle = Allure.getLifecycle();
lifecycle.updateTestCase(testResult -> testResult.setName("CHANGED_NAME"));
log.ifo("Changing test case name");
}
答案 1 :(得分:0)
尝试使用
AllureLifecycle lifecycle = Allure.getLifecycle();
//change test name to "CHANGED_NAME"
lifecycle.updateTestCase(testResult -> testResult.setName("CHANGED_NAME"));