2

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

Veeranna
  • 21
  • 1
  • 4

2 Answers2

3

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

try to use

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