如何为 TestNG.xml 中的 Class 提供别名
How to give alias name for the Class in TestNG.xml
我有 testng.xml 如下:
<classes>
<class name="com.tecnotree.clm.tests.CorporateHybridRegistrationTest" />
<class name="com.tecnotree.clm.tests.CorporatePostpaidRegistrationTest" />
</classes>
我在 @BeforeClass
中得到这个 class 名称并开始 extentReport
@BeforeClass(alwaysRun = true)
public void initializeLog() throws Exception
{
extentLog = extentReport.startTest(this.getClass().getName());
extentLog.log(LogStatus.INFO,"Started Test Execution for "+this.getClass().getName());
}
我一切正常,现在的问题是因为测试名称非常日志,它以相同的方式启动,我想给出我自己的名字。
例如:-测试名称作为 com.tecnotree.clm.tests.CorporatePostpaidRegistrationTest
哪位大神帮忙看看怎么做
我想要像 Corporate Prepaid Registration Test
这样的测试名称
com.tecnotree.clm.tests.CorporatePostpaidRegistrationTest
就是这样,因为你要求它:
this.getClass().getName()
但是您可以想象自定义名称有另一个自定义逻辑。例如,在一个伪代码中:
@ExtentReport(name="Corporate Prepaid Registration Test")
public class CorporatePostpaidRegistrationTest {
[...]
@BeforeClass(alwaysRun = true)
public void initializeLog() throws Exception {
ExtentReport report = this.getClass().getAnnotation(ExtentReport.class);
String testName = report != null ? report.name() : this.getClass().getName();
extentLog = extentReport.startTest(testName);
extentLog.log(LogStatus.INFO,"Started Test Execution for " + testName);
}
}
编辑:@ExtentReport
是自定义注释,不存在于某处。你必须自己创建它。
我有 testng.xml 如下:
<classes>
<class name="com.tecnotree.clm.tests.CorporateHybridRegistrationTest" />
<class name="com.tecnotree.clm.tests.CorporatePostpaidRegistrationTest" />
</classes>
我在 @BeforeClass
中得到这个 class 名称并开始 extentReport
@BeforeClass(alwaysRun = true)
public void initializeLog() throws Exception
{
extentLog = extentReport.startTest(this.getClass().getName());
extentLog.log(LogStatus.INFO,"Started Test Execution for "+this.getClass().getName());
}
我一切正常,现在的问题是因为测试名称非常日志,它以相同的方式启动,我想给出我自己的名字。
例如:-测试名称作为 com.tecnotree.clm.tests.CorporatePostpaidRegistrationTest
哪位大神帮忙看看怎么做
我想要像 Corporate Prepaid Registration Test
com.tecnotree.clm.tests.CorporatePostpaidRegistrationTest
就是这样,因为你要求它:
this.getClass().getName()
但是您可以想象自定义名称有另一个自定义逻辑。例如,在一个伪代码中:
@ExtentReport(name="Corporate Prepaid Registration Test")
public class CorporatePostpaidRegistrationTest {
[...]
@BeforeClass(alwaysRun = true)
public void initializeLog() throws Exception {
ExtentReport report = this.getClass().getAnnotation(ExtentReport.class);
String testName = report != null ? report.name() : this.getClass().getName();
extentLog = extentReport.startTest(testName);
extentLog.log(LogStatus.INFO,"Started Test Execution for " + testName);
}
}
编辑:@ExtentReport
是自定义注释,不存在于某处。你必须自己创建它。