Repository: cucumber/cucumber-jvm

Issue #2567: Feature selected with command line option "-Dcucumber.features" gets executed twice
Created: 2022-06-12T16:01:50Z
👓 What did you see?
A scenario of a feature file gets executed twice, when selecting it using the command line option -Dcucumber.features=<feature_file_path>.
✅ What did you expect to see?
Scenario gets only executed once.
📦 Which tool/library version are you using?
cucumber-jvm 7.3.4
🔬 How could we reproduce it?
I prepared a repo with a project demonstrating the effect: https://github.com/ctjdr/hellocucumber.
The project was created using the Maven Archtype-based generation as described in the cucumber-jvm tutorial.
I only changed the generated project by:

updating the Cucumber version to 7.3.4
adding a simple feature file with a single-step scenario hello.feature
implementing a simple step def for it that just prints out "Hello!" when executed.

Steps to reproduce the behavior:

$ git clone https://github.com/ctjdr/hellocucumber
$ cd hellocucumber
$ mvn test -Dcucumber.publish.quiet=true -Dcucumber.features=src/test/java/hellocucumber/hello.feature 

This results in an output like this:
Jun 12, 2022 5:55:06 PM io.cucumber.junit.platform.engine.DiscoverySelectorResolver warnWhenCucumberFeaturesPropertyIsUsed
WARNING: Discovering tests using the cucumber.features property. Other discovery selectors are ignored!
Please request/upvote/sponsor/ect better support for JUnit 5 discovery selectors.
See: https://github.com/cucumber/cucumber-jvm/pull/2498
Hello!
[INFO] Running hellocucumber.RunCucumberTest
Hello!

Scenario: Say hello # src/test/java/hellocucumber/hello.feature:2
  Then Say hello    # hellocucumber.StepDefinitions.say_hello()
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 s - in hellocucumber.RunCucumberTest
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Please note that Hello! is printed twice.
📚 Any additional context?
When using the annotation
@ConfigurationParameter(key = FEATURES_PROPERTY_NAME, value = "src/test/java/hellocucumber/hello.feature")
instead of the command line option, the scenario is only executed once, as expected.

Duplicate issue #2761: Duplicated test execution while using `cucumber.features` property
Created: 2023-05-25T08:41:43Z
It seems tests are executed twice via the cucumber.features property.
Project to reproduce the issue:  https://github.com/fslev/cucumber-showcase
Steps to reproduce the behavior:

Run Cucumber test scenarios using the cucumber.features property

mvn clean test -Dcucumber.features=classpath:io/example/Feature1.feature:3

Actual:
Running scenario: Feature 1 - Scenario 1_1
Running scenario: Feature 1 - Scenario 1_1

Scenario 1_1 is executed twice.
While using tags:
mvn clean verify -Dcucumber.filter.tags="@1"

... scenario is executed correctly, only once.
Thanks

Closing comment (2023-05-25T10:50:05Z): In your project Cucumber gets two test discovery/execution requests. One when Maven makes a discovery request. And a second one through the JUnit Platform Suite engine. Normally the request made by Maven fails to discover any tests because Maven only requests the discovery of classes. However by setting the  cucumber.features it will discover something.
So when using cucumber.features you must ensure that there is only a single execution of the Cucumber Engine.
Ultimately this comes down to a lack of proper support for the JUnit Platform in Maven (junit-team/junit5#2849) and IDEA. If that existed you would not have to use the JUnit Platform Suite Engine to run Cucumber.
Though I'm surprised you didn't see this warning:

  
    
      cucumber-jvm/cucumber-junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/DiscoverySelectorResolver.java
    
    
        Lines 39 to 44
      in
      b53204e
    
  
  
    

        
          
               log.warn( 
        

        
          
                   () -> "Discovering tests using the " + FEATURES_PROPERTY_NAME 
        

        
          
                           + " property. Other discovery selectors are ignored!\n" + 
        

        
          
                           "Please request/upvote/sponsor/ect better support for JUnit 5 discovery selectors.\n" + 
        

        
          
                           "See: https://github.com/cucumber/cucumber-jvm/pull/2498"); 
        

        
          
           } 
        
    
  


Duplicate of #2567, #2498.