java - 范围报告 4 未创建报告
问题描述
我正在尝试创建范围报告版本 v4.0.9 但无法这样做。下面的代码我写到了 setUp 类,它具有所有的 before 方法和 aftermethos,并且同一个类扩展到我正在执行测试的 Utilities 类。
这是setUp类的代码
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();
}
}
这是扩展到上述类的实用程序类。
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");
}
需要提到的几个要点现在我没有收到错误,在我收到空指针异常但现在没有错误之前。此外,代码运行良好,但没有生成范围报告。如果我把所有东西都放在一个类中,没有之前的测试和东西,就可以创建报告。不知道为什么会出错。
我真的很感谢你的帮助。
解决方案
我在阅读后得到了答案。
基本上我在没有静态变量的情况下进行了前测,因为由于其他全局变量,它必须静态启动。
下面的代码解决了我的问题。
@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");
}
推荐阅读
- anaconda - 如何找出橙色数据集中列中的唯一值和唯一值的数量?
- react-native - 运行测试时反应原生 customBubblingEventTypes 错误
- sql - 遍历表中的所有值并检查是否有任何值是日期时间类型,然后更改其格式
- java - 返回(不打印)字符串 Java 的所有排列
- dart - 相当于 Dart 中的 Java System.arraycopy?
- javascript - 谷歌地图 api 和 javascript 的新功能 - 切换 json 数据/图层
- angular - NGRX Effects + AngularFire 中的错误处理
- javascript - 潜在的无限循环:超过 10001 次迭代
- ios - 我可以使用 SecItemUpdate 更新 kSecAttrApplicationTag 吗?
- javascript - 如何使用其文档 ID 从 Firestore 获取多个文档?