0

I have two domain specific junit5 platform cucumber test suites.

A:

@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
}

and 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
}

The stepdefiniton classes are in the same package as each of the suite-classes. In both stepdefintions classes are some duplicate step definitions (just the method body is different) and used in the feature files.

    @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()));
        }
    }

If i run both in intellij idea by selecting just both suite classes, all tests run succesful. If i run all tests i get duplicate step execptions. (also in eclipse)

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)

I already tried a lot with forking on a class basis (in the run configuration) but this slows the other tests way too much down and other stuff. The step definitions should stay as they are (requirement). I know i could just rename them.

Is there a way to run those two suites "separately"? (without to change maven config and run config) I only want those two cucumber suite-classes to run separately (in diffrent threads? jvms?), preferably defined with an annotation or configuration property somewhere.

4
  • What is in stack trace with the duplicate step exception? Commented Nov 14, 2024 at 18:05
  • @M.P.Korstanje added it. Commented Nov 18, 2024 at 8:02
  • Cheers. This starts to sound like a bug, can you reproduce this minimally by using github.com/cucumber/cucumber-java-skeleton ? Commented Nov 18, 2024 at 14:54
  • edit: It starts to sound like a bug because I would expect both suites to run without duplicate step definition exceptions. As currently described it should just work. Commented Nov 18, 2024 at 15:09

1 Answer 1

0

Add the parallel thread configuration in 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>

Also create 2 suites in TestNG file

<!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>
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, thanks. But I preferably want a solution without explicit forking in maven.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.