范围报告 4 未创建报告

Extent Report 4 not creating report

我正在尝试创建范围报告版本 v4.0.9 但无法创建。 下面的代码是我写给 setUp class 的,它有所有的 before 方法和 aftermethos,同样的 class 扩展到我正在执行测试的实用程序 class。

这是设置代码class

public class AIG_SetUp {
    protected static ExtentLoggerReporter logger;
    protected static ExtentReports extent;
    protected static ExtentTest log;

     @BeforeTest(alwaysRun = true)
     public void starttest() {
            logger = new ExtentLoggerReporter(System.getProperty("user.dir"));
            extent = new ExtentReports();
            extent.attachReporter(logger);
            System.err.close(); // written to remove JAVA 9 incompatibility.. continued below
            System.setErr(System.out); // continue.. and remove the warnings
            extent.setSystemInfo("User Name" , "Sobhit");
     }

     @AfterMethod(alwaysRun = true)
     public void endReport(ITestResult result) {
          try {
               if (result.getStatus() == ITestResult.FAILURE) {
                    log.log(Status.FAIL , "Test cases Failed" + result.getName());
                    log.log(Status.FAIL , "Test cases Failed" + result.getThrowable());
               } else if (result.getStatus() == ITestResult.SKIP) {
                    log.log(Status.SKIP , "Test case skipped is" + result.getName());
               }
          } catch (Exception e) {
               e.printStackTrace();
          }
     }

     @AfterTest(alwaysRun = true)
     public void endReport() {
          extent.flush();

          }
     }

这里是实用程序 class,扩展到 class。

public class UtilitiesOps extends AIG_SetUp {

     @Test(groups = {"Core-Smoke"}, description = "List all media types")
     public void Verify_List_all_media_types() {
         extent.attachReporter(logger);
         extent = new ExtentReports();
         log = extent.createTest("List all media types");
         log.assignCategory("Utilities Operations");

     } 

有几点值得一提 现在我没有得到错误,在我得到空指针异常之前但现在没有错误。 代码也运行良好但不生成范围报告。 如果我把所有东西都放在一个 class 中,没有之前的测试和东西,就能够创建报告。不知道为什么会出错。

非常感谢您的帮助。

阅读后我得到了答案。

基本上我在没有静态变量的情况下进行了预测试,因为它必须静态启动,因为其他全局变量。

下面的代码解决了我的问题。

@BeforeTest(alwaysRun = true)
     public static void starttest() {
            logger = new ExtentLoggerReporter(System.getProperty("user.dir"));
            extent = new ExtentReports();
            extent.attachReporter(logger);
            System.err.close(); // written to remove JAVA 9 incompatibility.. continued below
            System.setErr(System.out); // continue.. and remove the warnings
            extent.setSystemInfo("User Name" , "Sobhit");
     }