0

Running Cucumber with JUnit 5 works ok as long as all feature files are run.

@Suite
@IncludeEngines("cucumber")
@ConfigurationParameter(key = Constants.FEATURES_PROPERTY_NAME, value = "src/main/features")
@ConfigurationParameter(key = Constants.GLUE_PROPERTY_NAME, value = "com/nedap/healthcare/administration/cucumber/glue")
@ConfigurationParameter(key = Constants.PLUGIN_PROPERTY_NAME, value = "pretty, html:target/cucumber.html")
@ConfigurationParameter(key = Constants.JUNIT_PLATFORM_NAMING_STRATEGY_PROPERTY_NAME, value = "long")
public class CucumberRunner {
}

But I you want to run just one feature

mvn compile test -Dcucumber.features=.../some.feature

Then that feature is executed, immediately followed by all features. This is best visible if print statements are placed in the before and after scenario hooks:

BeforeAll
Before
After
Before
After
AfterAll
[INFO] Running com.nedap.healthcare.administration.cucumber.CucumberRunner
BeforeAll

And then things start to go wrong, because the BeforeAll is not reentrant. (But that is not the problem, it should not be executed again.)

Interestingly the [INFO] line is not present before the first BeforeAll. It seems JUNit 5's Suite annotation is not working as it should.

Any suggestions what may be wrong?

1 Answer 1

0

A colleague found this https://github.com/cucumber/cucumber-jvm/issues/2567

It turns out the root of the problem is JUnit 5 support in Maven and Gradle.

The workaround we chose are two different CucumberRunner classes. One annotated with Suite to run all feature files, one without to run a single feature.

9
  • You found a solution, but a better one was found a little after the issue was resolved. github.com/cucumber/cucumber-jvm/tree/main/… Commented Jun 27 at 16:25
  • You should also not use @ConfigurationParameter(key = Constants.FEATURES_PROPERTY_NAME, value = "src/main/features") but instead use JUnit Suites annotations for selecting tests @SelectDirectory("src/main/features"). Commented Jun 27 at 16:26
  • Why is that second option better?
    – tbeernot
    Commented Jun 27 at 20:06
  • It uses JUnits API. So things like reruning failed scenarios also work (once you upgrade to 5.10.3). With cucumber.features Cucumber ignores anything JUnit asks. It's necessary to select a feature from the CLI with Maven, but that is the only use case. Commented Jun 27 at 20:21
  • Also, it gets rid of the big ass warning in your output. :D Commented Jun 27 at 20:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.