英文:
Unable to create extent reports in Java
问题
你好,我无法获取报告。我没有遇到任何错误,但报告没有生成。
public class Listners extends TestListenerAdapter{
public ExtentHtmlReporter htmlReporter;
public ExtentReports extent;
public ExtentTest test;
public void onStart (ITestContext testContext)
{
htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir")+"/test-output/myReport.html");
htmlReporter.config().setDocumentTitle("自动化报告");
htmlReporter.config().setReportName("Rest API 测试报告");
extent = new ExtentReports();
public void onTestSuccess(ITestResult testResult)
{
test = extent.createTest(testResult.getName());
test.log(Status.PASS, "测试用例通过 --" +testResult.getName());
}
public void onTestFailure(ITestResult testResult)
{
test = extent.createTest(testResult.getName());
test.log(Status.FAIL, "测试用例失败 --" +testResult.getName());
test.log(Status.FAIL, "测试用例失败 --" +testResult.getThrowable());
}
public void onTestSkipped(ITestResult testResult)
{
test = extent.createTest(testResult.getName());
test.log(Status.SKIP, "测试用例跳过 --" +testResult.getName());
}
public void onTestFlush(ITestContext testContext)
{
extent.flush();
}
}
英文:
HI I am unable to get the reports. I am not facing any kind of errors but reports are not generating.
public class Listners extends TestListenerAdapter{
public ExtentHtmlReporter htmlReporter;
public ExtentReports extent;
public ExtentTest test;
public void onStart (ITestContext testContext)
{
htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir")+"/test-output/myReport.html");
htmlReporter.config().setDocumentTitle("Automation Report");
htmlReporter.config().setReportName("Rest API Testing Report");
extent = new ExtentReports();
public void onTestSuccess(ITestResult testResult)
{
test = extent.createTest(testResult.getName());
test.log(Status.PASS, "Test Case Pass is --" +testResult.getName());
}
public void onTestFailure(ITestResult testResult)
{
test = extent.createTest(testResult.getName());
test.log(Status.FAIL, "Test Case Failed is --" +testResult.getName());
test.log(Status.FAIL, "Test Case Failed is --" +testResult.getThrowable());
}
public void onTestSkipped(ITestResult testResult)
{
test = extent.createTest(testResult.getName());
test.log(Status.SKIP, "Test Case Skipped is --" +testResult.getName());
}
public void onTestFlush(ITestContext testContext)
{
extent.flush();
}
答案1
得分: 0
如果我理解了这个问题,你只需要使用@Listeners
注解标记你的测试类,并将你的监听器类放入这个注解中。
@Listeners([你的监听器类名称].class)
public void [你的测试类名称] {
/*
*
* 一些测试
*
*/
}
英文:
If I understood the question, you just should marked your test class by @Listeners annotation and put your Listener class into this annotation.
@Listeners([your listener class name].class)
public void [your test class name] {
/*
*
* some tests
*
*/
}
专注分享java语言的经验与见解,让所有开发者获益!
评论