运行具有重复步骤定义的不同 Junit5 Cucumber 测试套件

问题描述 投票:0回答:1

我有两个特定领域的junit5平台黄瓜测试套件。

答:

@Suite
@IncludeEngines("cucumber")
@SelectPackages("de.bla.blubb1")
@SelectClasspathResource("de/bla/blubb1")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "de.bla.blubb1")
@ConfigurationParameter(key = PLUGIN_PUBLISH_QUIET_PROPERTY_NAME, value = "true")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty,json:target/blubb1cucumber.json")
public class RunBlubb1CucumberTest
{
    // nichts zu tun
}

和B:

@Suite
@IncludeEngines("cucumber")
@SelectPackages("de.bla.blubb2")
@SelectClasspathResource("de/bla/blubb2")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "de.bla.blubb2")
@ConfigurationParameter(key = PLUGIN_PUBLISH_QUIET_PROPERTY_NAME, value = "true")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty,json:target/blubb2cucumber.json")
public class RunBlubb2CucumberTest
{
    // nichts zu tun
}

stepdefiniton 类与每个套件类位于同一包中。 在这两个步骤定义类中都有一些重复的步骤定义(只是方法主体不同)并在功能文件中使用。

    @Gegebensei("Example")
    public void gegebenSeiExample(Map<String, Map<String, String>> map)
    {
        for (Entry<String, Map<String, String>> e : map.entrySet())
        {
            blabla.put(e.getKey(), new BlaMock(e.getValue()));
        }
    }

如果我通过仅选择两个套件类在 intellij idea 中运行两者,则所有测试都会成功运行。 如果我运行所有测试,我会得到重复的步骤执行。 (也在日食中)

DuplicateStepDefinitionException


io.cucumber.core.runner.DuplicateStepDefinitionException: Duplicate step definitions in de.bla.blubb1.StepDefsEingangsparameter.erstelle() and de.bla.blubb2.StepDefsEingangsparameter.erstelle()

    at io.cucumber.core.runner.CachingGlue.lambda$prepareGlue$3(CachingGlue.java:278)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at io.cucumber.core.runner.CachingGlue.prepareGlue(CachingGlue.java:272)
    at io.cucumber.core.runner.Runner.runPickle(Runner.java:72)
    at io.cucumber.junit.platform.engine.CucumberEngineExecutionContext.lambda$runTestCase$4(CucumberEngineExecutionContext.java:112)
    at io.cucumber.core.runtime.CucumberExecutionContext.lambda$runTestCase$5(CucumberExecutionContext.java:136)
    at io.cucumber.core.runtime.RethrowingThrowableCollector.executeAndThrow(RethrowingThrowableCollector.java:23)
    at io.cucumber.core.runtime.CucumberExecutionContext.runTestCase(CucumberExecutionContext.java:136)
    at io.cucumber.junit.platform.engine.CucumberEngineExecutionContext.runTestCase(CucumberEngineExecutionContext.java:109)
    at io.cucumber.junit.platform.engine.NodeDescriptor$PickleDescriptor.execute(NodeDescriptor.java:168)
    at io.cucumber.junit.platform.engine.NodeDescriptor$PickleDescriptor.execute(NodeDescriptor.java:90)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

我已经在类的基础上(在运行配置中)尝试了很多分叉,但这会减慢其他测试和其他东西的速度。 步骤定义应保持原样(要求)。我知道我可以重命名它们。

有没有办法“单独”运行这两个套件? (无需更改maven配置和运行配置) 我只希望这两个黄瓜套件类单独运行(在不同的线程中?jvms?),最好在某处使用注释或配置属性进行定义。

java cucumber junit5 cucumber-junit
1个回答
-1
投票

在maven-surefire-plugin中添加并行线程配置

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.2</version>
            <configuration>
                <parallel>methods</parallel>
                <threadCount>2</threadCount>
            </configuration>
        </plugin>
    </plugins>
</build>

同时在 TestNG 文件中创建 2 个套件

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suites>
    <!-- Suite 1 -->
    <suite name="Suite A">
        <test name="Test A1">
            <classes>
                <class name="de.bla.blubb1.RunBlubb1CucumberTest"/>
            </classes>
        </test>
    </suite>

    <!-- Suite 2 -->
    <suite name="Suite B">
        <test name="Test B1">
            <classes>
                <class name="de.bla.blubb2.RunBlubb2CucumberTest"/>
            </classes>
        </test>
    </suite>
</suites>
© www.soinside.com 2019 - 2024. All rights reserved.