简体   繁体   中英

Allure TestNG: Custom test method names while using @DataProvider

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

try to use

       AllureLifecycle lifecycle = Allure.getLifecycle();
//change test name to "CHANGED_NAME"
       lifecycle.updateTestCase(testResult -> testResult.setName("CHANGED_NAME"));

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");
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM