In cucumber-junit
library I use @CucumberOptions
to define feature files location:
package com.mycompany.cucumber;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(
plugin = ...,
features = "classpath:.", // my java step definitions are in package com.mycompany.cucumber
// but feature files directly in test resources
// resources/is_it_friday_yet.feature
tags = ...,
glue = ...
)
public class CucumberRunner {
}
I'm running my tests with custom gradle task cucumberTest
cucumberTest {
useJUnitPlatform()
}
After migrating to cucumber-junit-platform-engine
@CucumberOptions
are no longer supported.
package com.mycompany.cucumber;
import io.cucumber.junit.platform.engine.Cucumber;
@Cucumber
public class CucumberRunner {
}
I can make it work with replacing plugin
, tags
, glue
options with properties cucumber.filter.tags
, cucumber.glue
, cucumber.plugin
.
What about features
property? It works fine if I change feature files location to match package name i.e. resources/com/mycompany/cucumber/is_it_friday_yet.feature
. Still this is a simple case and I have many more test packages which are not placed in the same locations as source code and I cannot move them.
In cucumber-jvm v7 the @Cucumber
annotation is deprecated and you're encouraged to use the regular @Suite
annotation. This works for me:
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.mycompany.cucumber")
public class CucumberIT {
}
It picks up all my .feature files under the features/
dir in my resources folder (classpath)
Purpose of annotations:
@Suite - annotation from JUnit 5 to make this class a run configuration for test suite.
@IncludeEngines("cucumber") - tells JUnit 5 to use Cucumber test engine to run features.
@SelectClasspathResource("features") - to change the location of your feature files (if you do not add this annotation classpath of the current class will be used).
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.mycompany.cucumber") - this annotation specifies the path to steps definitions (java classes).
There are various other @Select*
annotations supported by junit-platform, I assume those work as well (though they're marked as experimental so subject to change): https://junit.org/junit5/docs/current/user-guide/#api-evolution-experimental-apis