人生若只如初见

TestNG使用groups测试报空指针

2020-04-13 9

TestNG用groups测试服务接口时报空指针异常NullPointer

报错信息

[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR]   AccountServiceTest.validateCaptcha:72 NullPointer
[INFO]
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

猜测问题发生原因

是因为maven指定组时,@BeforeMethod 和 @BeforeClass不会默认执行,
必须指定alwaysRun = true才可以。

@BeforeMethod(alwaysRun = true)
public void setUp() {
}

@Test(groups = {"util"})
public void test() {
}

修改之后进行测试没有异常。

参考资料

<https://stackoverflow.com/questions/23471424/can-not-run-a-specific-testng-group-via-maven>

<https://blog.csdn.net/kennin19840715/article/details/73844546>

0 0