@CucumberOptions in cucumber-junit-platform-engine
Asked Answered
Y

3

7

I'm trying to migrate my cucumber tests from cucumber-junit to cucumber-junit-platform-engine to be able to use new platform features. How do I redefine my runner to use old @CucumberOptions. I'm investigating the issue but can't seem to find the proper way yet.

Before I used such options:

@CucumberOptions(
  plugin = ...,
  features = ...,
  tags = ...,
  glue = ...
)

Is there a straighforward way to migrate it to platform-engine?

Yokel answered 29/10, 2020 at 8:53 Comment(1)
In my case, to use the plugin option, had to declare it in cucumber.properties, under src/test/resources as cucumber.plugin=<package_under_src_test_java>.<class_name>Kostman
M
10

I have been looking into JUnit5 and Cucumber 7.0 the past few days, I am only adding to your own answer.. documentation is scarce, this link has been a bless and docs

you dont have to use @IncludeEngines also notice how packages are referenced

@Suite
@SelectClasspathResource("com/rmdaw/cucumber/features")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.rmdaw.repository")

last thing you can place configuration into test/java/resources/junit-platform.properties inside you can have something like this:

cucumber.publish.quiet=true
cucumber.glue=com.rmdaw.cucumber
cucumber.plugin=pretty,\
            html:target/SystemTestReports/report.html,\
            json:target/SystemTestReports/report.json,\
            junit:target/SystemTestReports/junit.xml\ 
Meridith answered 26/11, 2021 at 19:13 Comment(0)
L
3

Until Junit5/#2416 is merged there is no 1-to-1 replacement. However if you only have a single class annotated with @CucumberOptions adding properties to junit-platform.properties should suffice.

EDIT: #2416 was merged and released. You can now use suites to run cucumber with different configurations. See cucumber-junit-platform docs.

Lynelllynelle answered 29/10, 2020 at 20:23 Comment(6)
What about projects with multiple runners? And how do I define features = ...,? I can't find such property for new library. I'll read about test discovery and try to figure it out. If you know how to do it then I'll appreciate help.Yokel
You'll have to start JUnit 5 multiple times with different discovery selectors.Lynelllynelle
You can read about that in the Junit documentation. And then you'll have to map that to Maven/Gradle. junit.org/junit5/docs/current/user-guide/…Lynelllynelle
This might be silly but where do I put the selector code? Let's say I had my feature files in some dir. When I used @CucumberOptions it was easy features=classpath:some/dir. Now I think I need to use URISelector but where do I actually put it?Yokel
I asked more specific question about features here.Yokel
Cheers. That helps!Lynelllynelle
Y
2

It looks like @Suite from junit-platform-engine with proper engine should be used instead of cucumber annotations.

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.example")
public class RunCucumberTest {
}

Kudos to @spmason answer.

Yokel answered 24/11, 2021 at 9:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.