0

Factory dataprovider test results.

package kill.me.later;

import static org.testng.Assert.assertTrue;

import org.testng.annotations.Test;

public class SomeTest {
    private int id = 0;
    private String account = "";

    public SomeTest(int id, String account) {
        this.id = id;
        this.account = account;
    }
    //test
    @Test
    public void firstTest() {
        System.out.println("Test #1 with data: "+id+". "+account);
        assertTrue(true);
    }

    @Test
    public void secondTest() {
        System.out.println("Test #2 with data: "+id+". "+account);
        assertTrue(true);
    }

    @Test
    public void thirdTest() {
        System.out.println("Test #3 with data: "+id+". "+account);
        assertTrue(true);
    }
}

Factory Class

package kill.me.later;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;

public class SampleFactory {

    @Factory(dataProvider="dp")
    public Object[] createInstances(int id, String account) {
        return new Object[] {new SomeTest(id, account)};
    }

    @DataProvider(name="dp")
    public static Object[][] dataProvider() {
        Object[][] dataArray = {
                {1, "user1"},
                {2, "user2"}
        };
        return dataArray;
    }

}

When I run below suite, I get results as below

LocalSuite
    ParticularTest
        SomeTest
            firstTest
            secondTest
            thirdTest
            firstTest(1)
            secondTest(2)
            thirdTest(3)

But I want results separated for each dataset ran against same class which has 3 test. like below

LocalSuite
    ParticularTest
        TestScenario1
            firstTest
            secondTest
            thirdTest
        TestScenario2
            firstTest(1)
            secondTest(2) 
            thirdTest(3)

xml suite xml suite xml suite xml suite xml suite xml suite xml suite xml suite xml suite xml suite xml suite xml suitexml suite xml suite xml suite xml suite

<suite name="LocalSuite" verbose="1">
 <test name="ParticularTest" group-by-instances="true">
 <classes>
 <class name="kill.me.later.SampleFactory"></class>
 </classes>
 </test>
 </suite>
bvr
  • 249
  • 2
  • 4
  • 15

0 Answers0