I have a simple test suite (Very simple for this example). I am using the @Factory notation over the constructor and a @DataProvider which returns an object[][] of cities(as many as 100)I run my tests on. in this example there are 3 @Test methods. If I don't append the test names with the city name, I would have an HTML report that simply lists 3 test methods over and over with no way to distinguish them.
I have attempted this SO example: Here.
My test class works perfectly. The problem I'm having is that when I override the ITest getMethodName() I get unexpected output.
My Code:
@Test(sequential = true)
public class ParcelSearchPage implements ITest{
private String cityClassName;
private String cityName;
private mTestCaseName = "";
@Factory(dataProvider="getCities")
public ParcelSearchPage(String className , String cityName){
this.cityClassName = className;
this.cityName = cityName;
}
@DataProvider
public Object[][] getCities(){
return new Object[][]FromAnotherMethod();
}
@Override //from ITest
public String getTestName() {
return this.mTestCaseName;
}
@BeforeMethod(alwaysRun = true)
public void testData(Method method) {
this.mTestCaseName = String.format("%s : %s" , this.cityClassName, method.getName());
}
@BeforeClass(alwaysRun = true)
public void startup(){
// init stuff
}
@Test
public void test1(){
}
@Test
public void test2{
}
@Test
public void test3{
}
}
I'm hoping this is detailed enough to get the example across.
Output:
Using cityClassNames Albany, Astoria, Bend
Opening the Html report I would expect a list as follows:
Albany: test1
Albany: test2
Albany: test3
Astoria: test1
Astoria: test2
Astoria: test3
Bend: test1
Bend: test2
Bend: test3
I am forcing group_by_instance in the testng.xml
What I am seeing in the Html report is this:
Albany: test1(Albany: test3)
Albany: test2(Albany: test3)
Albany: test3(Albany: test3)
Astoria: test1(Astoria: test3)
Astoria: test2(Astoria: test3)
Astoria: test3(Astoria: test3)
Bend: test1(Bend: test3)
Bend: test2(Bend: test3)
Bend: test3(Bend: test3)
I have spotted other post where folks have had similar problems (even the post I mentioned before hand)
I also tried this briefly in an @AfterClass method. The output was still problematic.
I don't understand how to rectify this. I've tested the string and the problem occurs in the getTestName() method. Even if I pass something simple like 'Hello' the Report will show Hello(Hello).
I think perhaps there could be a bug in the TestNG Java code.
Any solutions or guidance much appreciated.