我正在尝试通过几个并行的线程来运行我们的Cucumber JVM测试。 我正在使用标准的TastNG方法(通过套件XML文件) 我的xml文件是:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="BDD" parallel="methods" thread-count="3" data-provider-thread-count="3">
<test name="BDD">
<classes>
<class name="com.tests.bdd.SimpleBDDTests"></class>
</classes>
</test>
</suite>
我的测试课程是:
@CucumberOptions(features = "src/test/java/com/tests/bdd/simpleFeatures")
public class SimpleBDDTests {
private TestNGCucumberRunner tcr;
@BeforeClass(alwaysRun = true)
public void beforeClass() throws Exception {
tcr = new TestNGCucumberRunner(this.getClass());
}
@AfterClass(alwaysRun = true)
public void afterClass() {
tcr.finish();
}
@Test(dataProvider = "features")
public void feature(CucumberFeatureWrapper cucumberFeature) {
tcr.runCucumber(cucumberFeature.getCucumberFeature());
}
@DataProvider(parallel = true)
public Object[][] features() {
return tcr.provideFeatures();
}}
我的功能文件如下:
Feature: First test
@sanity
Scenario: First simple test
Given Base check step
我有4个功能文件,它们定义了相同的方案,只有一个步骤 - 给定基本检查步骤
当这些功能逐个执行时,它可以正常工作,但是当我尝试并行运行它们时,一切都会被破坏。 几乎所有这些特征都标记为失败,但有以下例外:
A scoping block is already in progress
java.lang.IllegalStateException: A scoping block is already in progress
at cucumber.runtime.java.guice.impl.SequentialScenarioScope.checkState(SequentialScenarioScope.java:64)
at cucumber.runtime.java.guice.impl.SequentialScenarioScope.enterScope(SequentialScenarioScope.java:52)
at cucumber.runtime.java.guice.impl.GuiceFactory.start(GuiceFactory.java:34)
at cucumber.runtime.java.JavaBackend.buildWorld(JavaBackend.java:123)
at cucumber.runtime.Runtime.buildBackendWorlds(Runtime.java:141)
at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:38)
at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
at cucumber.api.testng.TestNGCucumberRunner.runCucumber(TestNGCucumberRunner.java:63)
我知道可能会因为多线程调用同一步骤而发生 - 给定基本检查步骤
所以我的问题是如何解决这个问题?我如何并行运行这些测试?
PS:我知道应该可以通过JUnit + Maven surefire插件来实现,但它不适用于当前项目,我们需要通过TestNG实现这一目标。感谢。