我正在将范围报告用于 html 页面中的报告。在这里我面临一个问题。我需要从另一个班级获取 logger.info 消息。请仔细阅读以下代码,您将了解该问题,如果我错了,请纠正我
第一类:报告
package test;
public class Reports {
public ExtentReports extent;
public ExtentTest logger;
@BeforeSuite
public void startReport(){
extent = new ExtentReports (System.getProperty("user.dir") +"/test-output/STMExtentReport.html", true);
extent.loadConfig(new File(System.getProperty("user.dir")+"\\extent-config.xml"));
System.out.println("statrt report");
}
@AfterMethod
public void getResult(ITestResult result){
System.out.println("In ITresults : After method");
if(result.getStatus() == ITestResult.FAILURE){
logger.log(LogStatus.FAIL, "Test Case Failed is "+result.getName());
logger.log(LogStatus.FAIL, "Test Case Failed is "+result.getThrowable());
}else if(result.getStatus() == ITestResult.SKIP){
logger.log(LogStatus.SKIP, "Test Case Skipped is "+result.getName());
}
extent.endTest(logger);
}
@AfterSuite
public void endReport(){
extent.flush();
extent.close();
}
}
Class2 : - 新测试1
package testng;
public class NewTest1 extends Reports {
@Test
public void failTest(){
System.out.println("NewTest1 --> in Test fail testcase ");
logger = extent.startTest("failTest");
Assert.assertTrue(false);
logger.log(LogStatus.FAIL, "Test Case (failTest) Status is failed");
}
@Test
public void passTest(){
System.out.println("NewTest1 --> in Test pass testcase ");
logger = extent.startTest("passtest");
Assert.assertTrue(true);
logger.log(LogStatus.PASS, "Test Case (passtest) Status is failed");
skipTest();
}
Class3 :- NewTest2 包测试;
public class NewTest2{
//static ExtentReports extent;
static ExtentTest logg;
public static void skipTest(){
System.out.println("NewTest1 --> in Test skip testcase ");
logg.log(LogStatus.INFO, "Test case info will come here"); // Getting Nullpointer exception here
throw new SkipException("Skipping - This is not ready for testing ");
}
}