在尝试使用ITest获取唯一方法名称时遇到与此类似的问题。我有一个工厂方法,其中定义了数据提供程序以使用多个数据测试相同的测试用例。当我尝试为每个测试运行生成唯一的方法名称时,使用ITest和getTestName()附加负责每个测试运行的参数。我可以观察到我的TEST-TESTSUIT.xml文件正确生成了唯一的方法名称,如下所示。
"1.1.1.1_testmethod_parameter1" time="0.252"
"1.1.1.1_testmethod_parameter2" time="0.252"
但是在Index.html文件中,我可以观察到一个重复的值,该值负责所有测试的最后一次测试运行,如下所示。在index.html文件中,我可以看到对于所有测试结果都重复了一个值(1.1.1.20_login_parameter1)。
1.1.1.1_testmethod_parameter1 Test class: xxxxxxxx(1.1.1.20_login_parameter1) Test method: 1.1.1.1
1.1.1.1_testmethod_parameter1 Test class: xxxxxxxx(1.1.1.20_login_parameter1) Test method: 1.1.1.1
这可能是什么原因。这是testng方面的错误吗?我们可以从我们这边解决这个问题吗?我尝试了[1]中建议的各种方法。但是,任何事情对我都不起作用。赞赏您对这种行为的想法
类似于我尝试过的示例源代码如下
import org.testng.ITest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
import org.testng.annotations.Test;
import java.lang.reflect.Method;
public class TestAPIDD implements ITest
{
private String apiName;
String testInstanceName = "";
Parameters tp;
@Factory(dataProvider="apiDataProvider")
public TestAPIDD(String apiName, String userName) {
tp = new Parameters(apiName, userName);
this.apiName = tp.getAPIName();
}
@DataProvider(name = "apiDataProvider")
public Object[][] dataProvider() {
return new Object[][] { { "multiResourceAPI", "publisher1" }, { "ma lformedAPI", "publisher2" }, { "wsdlAPI","admin" } };
}
/**
* Constructor for the class TestAPIDD
*/
public TestAPIDD() {
}
/**
* Login Test
*/
@Test(description="1.1.1.1")
public void testLogin()
{
System.out.println("USER NAME: "+ tp.getUserName());
Assert.assertTrue(true);
}
@Test(description="1.1.1.2")
public void testAPICreate()
{
System.out.println("APINAME: "+ tp.getAPIName());
this.helperMethod();
Assert.assertTrue(true);
}
@BeforeMethod(alwaysRun = true)
public void changeTestCaseName(Method method) {
testInstanceName = method.getAnnotation(Test.class).description() + "_" + method.getName() +"_"+ apiName;
}
private void helperMethod() {
System.out.println("TEST HELPER");
}
/**
* Implementation of the getTestName in org.testng.ITest Interface.
* This will set the name for the test case in TEST-TestSuite.xml
*/
public String getTestName() {
return testInstanceName;
}
}
感谢您提供有关如何解决此问题的帮助。这是Testng方面的错误
答案 0 :(得分:0)
通过删除在index.html中类名末尾添加的testname值并在testng中添加新创建的CustomTestHTMLReporter类作为侦听器,可以编写CustomTestHTMLReporter.java类来解决此问题.xml文件。
使用的指南-[1]中的第11节“自定义报告”
[1]。 https://examples.javacodegeeks.com/enterprise-java/testng/testng-html-xml-reports-example/