【发布时间】:2014-06-26 23:15:38
【问题描述】:
场景是这样的: 运行我的 Cucumber 功能的 TestNG 测试运行程序。 有一个包含 WebBrowsers 的静态共享 Selenium WebDriver 池。 在 TestNG 测试结束时,我想关闭我的浏览器,所以我使用了 @AfterClass 注释。 进行了调用,代码运行以关闭浏览器,但实际上它们从未这样做。
如果我在调用后添加 Thread.sleep 一秒钟,浏览器会正常关闭。
JUnit 测试运行器每次都成功地关闭浏览器。 TestNG 有什么特别(错误)?
有问题的测试运行器的链接在这里:
随意克隆并亲自查看结果。
违规测试运行代码:
package uk.co.oliverdelange.testrunners.testng;
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import uk.co.oliverdelange.webbrowser.BrowserPool;
@CucumberOptions(tags = "~@Ignore",
features = "src/test/resources/uk/co/oliverdelange/cucumber/",
glue = "uk.co.oliverdelange.cucumber.tests",
format = {"pretty","html:CucumberReports/html/","json:CucumberReports/cucumber.json"},
monochrome = true
)
public class TestNGCucumberRunner extends AbstractTestNGCucumberTests {
@BeforeClass
public static void beforeClass() {
System.out.println("Do stuff here before the cucumber tests happen");
}
@AfterClass
public static void afterClass() { //FIXME why is this not being called?
System.out.println("Do stuff here after the cucumber tests happen");
System.out.println("Like shutting down all the web browsers...");
BrowserPool.closeAll();
//FIXME: JUnit manages to close the browser before closing the tests, but somehow TestNG doesn't - what!?
}
}
【问题讨论】:
-
我知道很多人喜欢 TestNG,但根据我的经验,它充满了 bug,而且很少被修复。很久以前,我自己的生命周期注释有问题(github.com/cbeust/testng/issues/425),甚至提出了一个从未合并的补丁。不幸的是,我只能建议不要使用 TestNG。 JUnit 有一个更干净的代码库,而 TestNG 是一个充满错误的烂摊子。我不知道您是否偶然发现了这样的错误。
标签: java junit selenium-webdriver cucumber testng