Skip to content

Commit e9a9bb3

Browse files
committed
Update documentation on running single scenarios with Gradle
1 parent 73c58bc commit e9a9bb3

File tree

6 files changed

+57
-21
lines changed

6 files changed

+57
-21
lines changed

Diff for: README.md

+46-13
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,8 @@ For available parameters see: `io.cucumber.junit.platform.engine.Constants`
5656

5757
## Run a subset of Features or Scenarios
5858

59-
Specify a particular scenario by *line*
60-
61-
@SelectClasspathResource(value = "io/cucumber/skeleton/belly.feature", line = 3)
62-
63-
In case you have multiple feature files or scenarios to run against repeat the
64-
annotation.
59+
### By Tag
60+
#### With the JUnit Suite Engine
6561

6662
You can also specify what to run by *tag*.
6763

@@ -80,31 +76,68 @@ Then add an annotation to `RunCucumberTest`.
8076
@IncludeTags("Zucchini")
8177
```
8278

79+
#### With Maven
80+
8381
When using Maven, tags can be selected from the CLI using the `groups` and `excludedGroups` parameters. These take a
8482
[JUnit5 Tag Expression](https://junit.org/junit5/docs/current/user-guide/#running-tests-tag-expressions).
8583
Note: When using JUnit, the `@` is not part of the tag.
8684

87-
```
85+
```shell
8886
mvn verify -DexcludedGroups="Haricots" -Dgroups="Zucchini | Gherkin"
8987
```
9088

91-
### Running a single scenario or feature
89+
#### With Gradle
90+
91+
When using Gradle, tags can be selected through the [build configuration](https://docs.gradle.org/current/userguide/java_testing.html#test_grouping). These take a [JUnit5 Tag Expression](https://junit.org/junit5/docs/current/user-guide/#running-tests-tag-expressions).
92+
Note: When using JUnit, the `@` is not part of the tag.
93+
94+
```kotlin
95+
tasks.withType<Test>().configureEach {
96+
useJUnitPlatform {
97+
includeTags("Zucchini | Gherkin")
98+
excludeTags("Haricots")
99+
}
100+
}
101+
```
102+
103+
### By line
104+
105+
#### With the JUnit Suite Engine
106+
107+
Specify a particular scenario by *line*
92108

93-
Maven and Gradle do not (yet) support selecting single features or scenarios
109+
@SelectClasspathResource(value = "io/cucumber/skeleton/belly.feature", line = 3)
110+
111+
In case you have multiple feature files or scenarios to run against repeat the
112+
annotation.
113+
114+
#### With Maven
115+
116+
Maven does not (yet) support selecting single features or scenarios
94117
with JUnit selectors. As a work around the `cucumber.features` property can be
95118
used. Because this property will cause Cucumber to ignore any other selectors
96119
from JUnit it is prudent to only execute the Cucumber engine.
97120

98-
#### With Maven
99-
100121
To select the scenario on line 3 of the `belly.feature` file use:
101122

102-
```
123+
```shell
103124
./mvnw test -Dsurefire.includeJUnit5Engines=cucumber -Dcucumber.features=src/test/resources/io/cucumber/skeleton/belly.feature:3
104125
```
105126

106127
Note: Add `-Dcucumber.plugin=pretty` to get a more detailed output during test execution.
107128

108129
#### With Gradle
109130

110-
TODO: (I don't know how to do this. Feel free to send a pull request. ;))
131+
Gradle does not (yet) support selecting single features or scenarios
132+
with JUnit selectors. As a work around the `cucumber.features` property can be
133+
used. Because this property will cause Cucumber to ignore any other selectors
134+
from JUnit it is prudent to only execute the Cucumber engine.
135+
136+
```shell
137+
./gradlew test --rerun-tasks --info -Dcucumber.features=src/test/resources/io/cucumber/skeleton/belly.feature:3
138+
```
139+
140+
Note: Add `-Dcucumber.plugin=pretty` to get a more detailed output during test execution.
141+
Note: Because both the Suite Engine and the Cucumber Engine are included, this
142+
will run tests twice. (If you know how to prevent this, please send a pull
143+
request).

Diff for: gradle/build.gradle.kts

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ repositories {
2020

2121
tasks.withType<Test> {
2222
useJUnitPlatform()
23+
24+
// Pass selected system properties to Cucumber
25+
systemProperty("cucumber.features", System.getProperty("cucumber.features"))
26+
systemProperty("cucumber.filter.tags", System.getProperty("cucumber.filter.tags"))
27+
systemProperty("cucumber.filter.name", System.getProperty("cucumber.filter.name"))
28+
systemProperty("cucumber.plugin", System.getProperty("cucumber.plugin"))
29+
2330
// Work around. Gradle does not include enough information to disambiguate
2431
// between different examples and scenarios.
2532
systemProperty("cucumber.junit-platform.naming-strategy", "long")

Diff for: gradle/src/test/java/io/cucumber/skeleton/RunCucumberTest.java

-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
import org.junit.platform.suite.api.Suite;
77

88
import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME;
9-
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
109

1110
@Suite
1211
@IncludeEngines("cucumber")
1312
@SelectPackages("io.cucumber.skeleton")
1413
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
15-
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "io.cucumber.skeleton")
1614
public class RunCucumberTest {
1715
}

Diff for: gradle/src/test/resources/junit-platform.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# Change this to false to display the Cucumber Reports banner
2-
cucumber.publish.quiet=true
1+
# Cucumber searches this package for your step definitions, ect
2+
cucumber.glue=io.cucumber.skeleton

Diff for: maven/src/test/java/io/cucumber/skeleton/RunCucumberTest.java

-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
import org.junit.platform.suite.api.SelectPackages;
66
import org.junit.platform.suite.api.Suite;
77

8-
import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME;
98
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
109

1110
@Suite
1211
@IncludeEngines("cucumber")
1312
@SelectPackages("io.cucumber.skeleton")
14-
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
1513
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "io.cucumber.skeleton")
1614
public class RunCucumberTest {
1715
}

Diff for: maven/src/test/resources/junit-platform.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# Change this to false to display the Cucumber Reports banner
2-
cucumber.publish.quiet=true
1+
# Cucumber searches this package for your step definitions, ect
2+
cucumber.glue=io.cucumber.skeleton

0 commit comments

Comments
 (0)