有可能创建自定义处理测试操作,例如:onTestStart
,onTestSuccess
,onTestFailure
等。可以使用TestNG自定义侦听器(here is an article about this)处理它们
但所有配置失败,跳过都不会被它处理,例如使用注释@BeforeTest
,@BeforeClass
,@AfterClass
等定义的方法。我有这样的日志:
FAILED CONFIGURATION: @BeforeTest setUp
org.testng.internal.thread.ThreadTimeoutException: Method org.testng.internal.ConfigurationMethod.setUp() didn't finish within the time-out 10000
...
SKIPPED CONFIGURATION: @BeforeClass openModule1
SKIPPED CONFIGURATION: @AfterClass closeModule1
SKIPPED CONFIGURATION: @BeforeClass openModule2
SKIPPED CONFIGURATION: @AfterClass closeModule2
SKIPPED: testOpenTabs
SKIPPED: testPrint
SKIPPED: testFilterDataRequest
是否有可能为配置操作创建侦听器?
答案 0 :(得分:0)
所有这些都是通过IConfigurationListener
完成的。 ConfigurationListener类看起来像这样:
public class ConfigurationListener implements IConfigurationListener {
@Override
public void onConfigurationSuccess(ITestResult itr) {
Logger.log("LOG From ConfigurationListener onConfigurationSuccess:: ");
}
@Override
public void onConfigurationFailure(ITestResult itr) {
Logger.log("LOG From ConfigurationListener onConfigurationFailure:: ");
}
@Override
public void onConfigurationSkip(ITestResult itr) {
Logger.log("LOG From ConfigurationListener onConfigurationSkip:: ");
}
}
并且不要忘记为TestNG提供听众,例如通过在基础测试类中使用注释:
@Listeners({ TestListener.class, ConfigurationListener.class})
public class TestBase {
...
以下是nice article about different listeners
中的testng