Skip to content

Update documentation on running single scenarios with Gradle #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 46 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,8 @@ For available parameters see: `io.cucumber.junit.platform.engine.Constants`

## Run a subset of Features or Scenarios

Specify a particular scenario by *line*

@SelectClasspathResource(value = "io/cucumber/skeleton/belly.feature", line = 3)

In case you have multiple feature files or scenarios to run against repeat the
annotation.
### By Tag
#### With the JUnit Suite Engine

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

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

#### With Maven

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

```
```shell
mvn verify -DexcludedGroups="Haricots" -Dgroups="Zucchini | Gherkin"
```

### Running a single scenario or feature
#### With Gradle

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).
Note: When using JUnit, the `@` is not part of the tag.

```kotlin
tasks.withType<Test>().configureEach {
useJUnitPlatform {
includeTags("Zucchini | Gherkin")
excludeTags("Haricots")
}
}
```

### By line

#### With the JUnit Suite Engine

Specify a particular scenario by *line*

Maven and Gradle do not (yet) support selecting single features or scenarios
@SelectClasspathResource(value = "io/cucumber/skeleton/belly.feature", line = 3)

In case you have multiple feature files or scenarios to run against repeat the
annotation.

#### With Maven

Maven does not (yet) support selecting single features or scenarios
with JUnit selectors. As a work around the `cucumber.features` property can be
used. Because this property will cause Cucumber to ignore any other selectors
from JUnit it is prudent to only execute the Cucumber engine.

#### With Maven

To select the scenario on line 3 of the `belly.feature` file use:

```
```shell
./mvnw test -Dsurefire.includeJUnit5Engines=cucumber -Dcucumber.features=src/test/resources/io/cucumber/skeleton/belly.feature:3
```

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

#### With Gradle

TODO: (I don't know how to do this. Feel free to send a pull request. ;))
Gradle does not (yet) support selecting single features or scenarios
with JUnit selectors. As a work around the `cucumber.features` property can be
used. Because this property will cause Cucumber to ignore any other selectors
from JUnit it is prudent to only execute the Cucumber engine.

```shell
./gradlew test --rerun-tasks --info -Dcucumber.features=src/test/resources/io/cucumber/skeleton/belly.feature:3
```

Note: Add `-Dcucumber.plugin=pretty` to get a more detailed output during test execution.
Note: Because both the Suite Engine and the Cucumber Engine are included, this
will run tests twice. (If you know how to prevent this, please send a pull
request).
7 changes: 7 additions & 0 deletions gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ repositories {

tasks.withType<Test> {
useJUnitPlatform()

// Pass selected system properties to Cucumber
systemProperty("cucumber.features", System.getProperty("cucumber.features"))
systemProperty("cucumber.filter.tags", System.getProperty("cucumber.filter.tags"))
systemProperty("cucumber.filter.name", System.getProperty("cucumber.filter.name"))
systemProperty("cucumber.plugin", System.getProperty("cucumber.plugin"))

// Work around. Gradle does not include enough information to disambiguate
// between different examples and scenarios.
systemProperty("cucumber.junit-platform.naming-strategy", "long")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
import org.junit.platform.suite.api.Suite;

import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME;
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;

@Suite
@IncludeEngines("cucumber")
@SelectPackages("io.cucumber.skeleton")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "io.cucumber.skeleton")
public class RunCucumberTest {
}
4 changes: 2 additions & 2 deletions gradle/src/test/resources/junit-platform.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Change this to false to display the Cucumber Reports banner
cucumber.publish.quiet=true
# Cucumber searches this package for your step definitions, ect
cucumber.glue=io.cucumber.skeleton
2 changes: 0 additions & 2 deletions maven/src/test/java/io/cucumber/skeleton/RunCucumberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.Suite;

import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME;
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;

@Suite
@IncludeEngines("cucumber")
@SelectPackages("io.cucumber.skeleton")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "io.cucumber.skeleton")
public class RunCucumberTest {
}
4 changes: 2 additions & 2 deletions maven/src/test/resources/junit-platform.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Change this to false to display the Cucumber Reports banner
cucumber.publish.quiet=true
# Cucumber searches this package for your step definitions, ect
cucumber.glue=io.cucumber.skeleton
Loading