NullPointerException与Testng实现范围报告

时间:2018-07-23 23:03:23

标签: java multithreading nullpointerexception testng extentreports

我编写的第一个示例onTestStart方法效果很好,但是第二个示例给了我NullPointerException。我很难理解它如何获得parallel="methods" thread-count="2"
我正在用TestNG public class ExtentTestNGITestListener implements ITestListener { private static ExtentReports extent = ExtentManager.getInstance(); private static ThreadLocal<ExtentTest> parentTest = new ThreadLocal<>(); private static ThreadLocal<ExtentTest> test = new ThreadLocal<>(); @Override public synchronized void onStart(ITestContext context) { ExtentTest parent = extent.createTest(getClass().getName()); parentTest.set(parent); } //no null pointer @Override public synchronized void onTestStart(ITestResult result) { ExtentTest parent = extent.createTest(getClass().getName()); ExtentTest child = parent.createNode(result.getMethod().getMethodName()); test.set(child); } //NullPointerException @Override public synchronized void onTestStart(ITestResult result) { ExtentTest child = parentTest.get().createNode(result.getMethod().getMethodName()); test.set(child); } //testng.xml file <suite name="Suite" parallel="methods" thread-count="2">

执行
xmlstarlet ed -u 'value to change' -v newValue source.xml

我了解parentTest在堆上,而本地人在堆上,但是我不明白为什么当我做set()时paretTest.get()会返回null。

感谢您的任何投入。

0 个答案:

没有答案