【发布时间】:2019-03-18 00:57:33
【问题描述】:
我有 3 节课。 Test1、Test2 和基类。 Test1 和 Test2 扩展基类。当我使用 TestNg xml 执行这两个类时,@BeforeClass 失败并出现空指针异常。正在生成 test1 的报告。也没有范围报告它的工作正常。请帮帮我
=====================================基类========= ======================
public class Base
{
public ExtentReports reports;
public ExtentTest logger;
@BeforeClass
public void startBrowser()
{
String name= LocalDateTime.now().format(DateTimeFormatter.ofPattern("ddMMMYY_HHmmss"));
logger = reports.createTest("Test1"+name);
System.out.println("Started Test1");
}
@BeforeSuite
public void initialSetup()
{
String name= LocalDateTime.now().format(DateTimeFormatter.ofPattern("ddMMMYY_HHmmss"));
ExtentHtmlReporter extent = new ExtentHtmlReporter(new File("./Reports/"+name+".html"));
reports = new ExtentReports();
reports.attachReporter(extent);
}
@AfterClass
public void end()
{
reports.flush();
}
}
============================Test1 class================== ===
public class Test1 extends Base{
@Test
public void TestCase()
{
logger.info("Test1");
}
}
====================Test2 class======================== ====
public class Test2 extends Base{
@Test
public void f()
{
System.out.println("Started Test2");
}
}
【问题讨论】: