Skip to content

Commit 1d73b7d

Browse files
committed
[Junit Platform] Support cucumber.filter.name
A typical way to run a single Cucumber test from the command line is to use a filter. The Cucumber Engine already supported `cucumber.filter.tags` but did not yet support `cucumber.filter.name`. This filter can be used in `junit-platform.properties`, the CLI (e.g. `mvn test -Dcucumber.filter.name="^Hello (World|Cucumber)$"` and in any way properties can be used with the JUnit Platform.
1 parent bd576bd commit 1d73b7d

File tree

9 files changed

+177
-60
lines changed

9 files changed

+177
-60
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## [Unreleased] (In Git)
99

1010
### Added
11-
11+
* [Junit Platform] Support cucumber.filter.name ([#2065](https://github.com/cucumber/cucumber-jvm/issues/2065) M.P. Korstanje)
12+
1213
### Changed
1314

1415
### Deprecated
1516

1617
### Removed
1718

1819
### Fixed
20+
* [Core] Generate valid parameter names in snippets ([#2029](https://github.com/cucumber/cucumber-jvm/issues/2029) M.P. Korstanje)
1921

2022
## [6.1.1] (2020-06-12)
2123

core/README.md

+34-11
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,49 @@ Note that options provided by `@CucumberOptions` take precedence over the
1515
properties file and CLI arguments take precedence over all.
1616

1717
Note that the `cucumber-junit-platform-engine` is provided with properties
18-
by the Junit Platform rather then Cucumber. See
18+
by the Junit Platform rather than Cucumber. See
1919
[junit-platform-engine Configuration Options](../junit-platform-engine#configuration-options)
2020
for more information.
2121

2222
Supported properties are:
2323

2424
```
25-
cucumber.ansi-colors.disabled= # true or false. default: false
26-
cucumber.execution.dry-run= # true or false. default: false
27-
cucumber.execution.limit= # number of scenarios to execute (CLI only).
25+
cucumber.ansi-colors.disabled= # true or false. default: false
26+
27+
cucumber.execution.dry-run= # true or false. default: false
28+
29+
cucumber.execution.limit= # number of scenarios to execute (CLI only).
30+
2831
cucumber.execution.order= # lexical, reverse, random or random:[seed] (CLI only). default: lexical
32+
2933
cucumber.execution.strict= # true or false. default: false.
34+
3035
cucumber.execution.wip= # true or false. default: false.
31-
cucumber.features= # command separated paths to feature files. example: path/to/example.feature, path/to/other.feature
32-
cucumber.filter.name= # regex. example: .*Hello.*
33-
cucumber.filter.tags= # tag expression. example: @smoke and not @slow
34-
cucumber.glue= # comma separated package names. example: com.example.glue
35-
cucumber.plugin= # comma separated plugin strings. example: pretty, json:path/to/report.json
36-
cucumber.object-factory= # object factory class name. example: com.example.MyObjectFactory
37-
cucumber.snippet-type= # underscore or camelcase. default: underscore
36+
# Fails if there any passing scenarios
37+
# CLI only.
38+
39+
cucumber.features= # command separated paths to feature files.
40+
# example: path/to/example.feature, path/to/other.feature
41+
42+
cucumber.filter.name= # a regular expression
43+
# only scenarios with matching names are executed.
44+
# example: ^Hello (World|Cucumber)$
45+
46+
cucumber.filter.tags= # a cucumber tag expression.
47+
# only scenarios with matching tags are executed.
48+
# example: @Cucumber and not (@Gherkin or @Zucchini)
49+
50+
cucumber.glue= # comma separated package names.
51+
# example: com.example.glue
52+
53+
cucumber.plugin= # comma separated plugin strings.
54+
# example: pretty, json:path/to/report.json
55+
56+
cucumber.object-factory= # object factory class name.
57+
# example: com.example.MyObjectFactory
58+
59+
cucumber.snippet-type= # underscore or camelcase.
60+
# default: underscore
3861
```
3962

4063
Each property also has an `UPPER_CASE` and `snake_case` variant. For example

core/src/main/java/io/cucumber/core/options/Constants.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,20 @@ public final class Constants {
9191
/**
9292
* Property name used to set name filter: {@value}
9393
* <p>
94-
* Filters features based on the provided regex pattern.
94+
* Filters scenarios by name based on the provided regex pattern e.g:
95+
* {@code ^Hello (World|Cucumber)$}. Scenarios that do not match the
96+
* expression are not executed.
9597
* <p>
96-
* By default no features are filtered
98+
* By default all scenarios are executed
9799
*/
98100
public static final String FILTER_NAME_PROPERTY_NAME = "cucumber.filter.name";
101+
99102
/**
100103
* Property name used to set tag filter: {@value}
101104
* <p>
102-
* Filters scenarios based on the provided tag expression e.g:
103-
* {@code @Integration and not @Ignored}. Scenarios that do not match the
104-
* expression are not executed.
105+
* Filters scenarios by tag based on the provided tag expression e.g:
106+
* {@code @Cucumber and not (@Gherkin or @Zucchini)}. Scenarios that do not
107+
* match the expression are not executed.
105108
* <p>
106109
* By default all scenarios are executed
107110
*/

core/src/main/resources/io/cucumber/core/options/USAGE.txt

+30-7
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,41 @@ Supported properties are:
110110

111111
```
112112
cucumber.ansi-colors.disabled= # true or false. default: false
113+
113114
cucumber.execution.dry-run= # true or false. default: false
115+
114116
cucumber.execution.limit= # number of scenarios to execute (CLI only).
117+
115118
cucumber.execution.order= # lexical, reverse, random or random:[seed] (CLI only). default: lexical
119+
116120
cucumber.execution.strict= # true or false. default: false.
121+
117122
cucumber.execution.wip= # true or false. default: false.
118-
cucumber.features= # command separated paths to feature files. example: path/to/example.feature, path/to/other.feature
119-
cucumber.filter.name= # regex. example: .*Hello.*
120-
cucumber.filter.tags= # tag expression. example: @smoke and not @slow
121-
cucumber.glue= # comma separated package names. example: com.example.glue
122-
cucumber.plugin= # comma separated plugin strings. example: pretty, json:path/to/report.json
123-
cucumber.object-factory= # object factory class name. example: com.example.MyObjectFactory
124-
cucumber.snippet-type= # underscore or camelcase. default: underscore
123+
# Fails if there any passing scenarios
124+
# CLI only.
125+
126+
cucumber.features= # command separated paths to feature files.
127+
# example: path/to/example.feature, path/to/other.feature
128+
129+
cucumber.filter.name= # a regular expression
130+
# only scenarios with matching names are executed.
131+
# example: ^Hello (World|Cucumber)$
132+
133+
cucumber.filter.tags= # a cucumber tag expression.
134+
# only scenarios with matching tags are executed.
135+
# example: @Cucumber and not (@Gherkin or @Zucchini)
136+
137+
cucumber.glue= # comma separated package names.
138+
# example: com.example.glue
139+
140+
cucumber.plugin= # comma separated plugin strings.
141+
# example: pretty, json:path/to/report.json
142+
143+
cucumber.object-factory= # object factory class name.
144+
# example: com.example.MyObjectFactory
145+
146+
cucumber.snippet-type= # underscore or camelcase.
147+
# default: underscore
125148
```
126149

127150
Each property also has an `UPPER_CASE` and `snake_case` variant. For example

junit-platform-engine/README.md

+18-14
Original file line numberDiff line numberDiff line change
@@ -170,49 +170,53 @@ Note: The `@` is not included.
170170
## Configuration Options ##
171171

172172
Cucumber receives its configuration from the JUnit platform. To see how these
173-
can be supplied see the JUnit documentation [4.5. Configuration Parameters](https://junit.org/junit5/docs/current/user-guide/#running-tests-config-params).
173+
can be supplied; see the JUnit documentation [4.5. Configuration Parameters](https://junit.org/junit5/docs/current/user-guide/#running-tests-config-params).
174174
For documentation see [Constants](src/main/java/io/cucumber/junit/platform/engine/Constants.java).
175175

176176
```
177177
cucumber.ansi-colors.disabled= # true or false. default: false
178178
179+
cucumber.filter.name= # a regular expression
180+
# only scenarios with matching names are executed.
181+
# example: ^Hello (World|Cucumber)$
182+
179183
cucumber.filter.tags= # a cucumber tag expression.
180-
# only matching scenarios are executed.
181-
# example: @integration and not @disabled
182-
184+
# only scenarios with matching tags are executed.
185+
# example: @Cucumber and not (@Gherkin or @Zucchini)
186+
183187
cucumber.glue= # comma separated package names.
184188
# example: com.example.glue
185-
189+
186190
cucumber.plugin= # comma separated plugin strings.
187191
# example: pretty, json:path/to/report.json
188-
192+
189193
cucumber.object-factory= # object factory class name.
190194
# example: com.example.MyObjectFactory
191-
195+
192196
cucumber.snippet-type= # underscore or camelcase.
193197
# default: underscore
194-
198+
195199
cucumber.execution.dry-run= # true or false.
196200
# default: false
197-
201+
198202
cucumber.execution.parallel.enabled= # true or false.
199203
# default: false
200-
204+
201205
cucumber.execution.parallel.config.strategy= # dynamic, fixed or custom.
202206
# default: dynamic
203-
207+
204208
cucumber.execution.parallel.config.fixed.parallelism= # positive integer.
205209
# example: 4
206-
210+
207211
cucumber.execution.parallel.config.dynamic.factor= # positive double.
208212
# default: 1.0
209-
213+
210214
cucumber.execution.parallel.config.custom.class= # class name.
211215
# example: com.example.MyCustomParallelStrategy
212216
213217
cucumber.execution.exclusive-resources.<tag-name>.read-write= # a comma seperated list of strings
214218
# example: resource-a, resource-b
215-
219+
216220
cucumber.execution.exclusive-resources.<tag-name>.read= # a comma seperated list of strings
217221
# example: resource-a, resource-b
218222

junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/Constants.java

+24-3
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,36 @@ public final class Constants {
2828
* By default, dry-run is disabled
2929
*/
3030
public static final String EXECUTION_DRY_RUN_PROPERTY_NAME = io.cucumber.core.options.Constants.EXECUTION_DRY_RUN_PROPERTY_NAME;
31+
3132
/**
3233
* Tag replacement pattern for the exclusive resource templates: {@value}
3334
*
3435
* @see #EXECUTION_EXCLUSIVE_RESOURCES_READ_WRITE_TEMPLATE
3536
*/
3637
public static final String EXECUTION_EXCLUSIVE_RESOURCES_TAG_TEMPLATE_VARIABLE = "<tag-name>";
38+
39+
/**
40+
* Property name used to set name filter: {@value}
41+
* <p>
42+
* Filters features by name based on the provided regex pattern e.g:
43+
* {@code ^Hello (World|Cucumber)$}. Scenarios that do not match the
44+
* expression are not executed.
45+
* <p>
46+
* By default all scenarios are executed
47+
*/
48+
public static final String FILTER_NAME_PROPERTY_NAME = io.cucumber.core.options.Constants.FILTER_NAME_PROPERTY_NAME;
49+
3750
/**
3851
* Property name used to set tag filter: {@value}
3952
* <p>
40-
* Filters scenarios based on the provided tag expression e.g:
41-
* {@code @Integration and not @Ignored}. Scenarios that did not match the
42-
* expression will be rendered by JUnit as skipped.
53+
* Filters scenarios by tag based on the provided tag expression e.g:
54+
* {@code @Cucumber and not (@Gherkin or @Zucchini)}. Scenarios that do not
55+
* match the expression are not executed.
4356
* <p>
4457
* By default all scenarios are executed
4558
*/
4659
public static final String FILTER_TAGS_PROPERTY_NAME = io.cucumber.core.options.Constants.FILTER_TAGS_PROPERTY_NAME;
60+
4761
/**
4862
* Property name to set the glue path: {@value}
4963
* <p>
@@ -53,6 +67,7 @@ public final class Constants {
5367
* @see io.cucumber.core.feature.GluePath
5468
*/
5569
public static final String GLUE_PROPERTY_NAME = io.cucumber.core.options.Constants.GLUE_PROPERTY_NAME;
70+
5671
/**
5772
* Property name to enable plugins: {@value}
5873
* <p>
@@ -76,13 +91,15 @@ public final class Constants {
7691
* registration of 3rd party plugins.
7792
*/
7893
public static final String PLUGIN_PROPERTY_NAME = io.cucumber.core.options.Constants.PLUGIN_PROPERTY_NAME;
94+
7995
/**
8096
* Property name to select custom object factory implementation: {@value}
8197
* <p>
8298
* By default, if a single object factory is available on the class path
8399
* that object factory will be used.
84100
*/
85101
public static final String OBJECT_FACTORY_PROPERTY_NAME = io.cucumber.core.options.Constants.OBJECT_FACTORY_PROPERTY_NAME;
102+
86103
/**
87104
* Property name to control naming convention for generated snippets:
88105
* {@value}
@@ -92,6 +109,7 @@ public final class Constants {
92109
* By defaults are generated using the under score naming convention.
93110
*/
94111
public static final String SNIPPET_TYPE_PROPERTY_NAME = io.cucumber.core.options.Constants.SNIPPET_TYPE_PROPERTY_NAME;
112+
95113
/**
96114
* Property name used to enable parallel test execution: {@value}
97115
* <p>
@@ -102,6 +120,7 @@ public final class Constants {
102120
static final String EXECUTION_EXCLUSIVE_RESOURCES_PREFIX = "cucumber.execution.exclusive-resources.";
103121

104122
static final String READ_WRITE_SUFFIX = ".read-write";
123+
105124
/**
106125
* Property template used to describe a mapping of tags to exclusive
107126
* resources: {@value}
@@ -131,6 +150,7 @@ public final class Constants {
131150
public static final String EXECUTION_EXCLUSIVE_RESOURCES_READ_WRITE_TEMPLATE = EXECUTION_EXCLUSIVE_RESOURCES_PREFIX
132151
+ EXECUTION_EXCLUSIVE_RESOURCES_TAG_TEMPLATE_VARIABLE + READ_WRITE_SUFFIX;
133152
static final String READ_SUFFIX = ".read";
153+
134154
/**
135155
* Property template used to describe a mapping of tags to exclusive
136156
* resources: {@value}
@@ -143,6 +163,7 @@ public final class Constants {
143163
+ EXECUTION_EXCLUSIVE_RESOURCES_TAG_TEMPLATE_VARIABLE + READ_SUFFIX;
144164

145165
static final String PARALLEL_CONFIG_PREFIX = "cucumber.execution.parallel.config.";
166+
146167
/**
147168
* Property name used to determine the desired configuration strategy:
148169
* {@value}

junit-platform-engine/src/main/java/io/cucumber/junit/platform/engine/CucumberEngineOptions.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
import java.util.Arrays;
1515
import java.util.Collections;
1616
import java.util.List;
17+
import java.util.Optional;
18+
import java.util.regex.Pattern;
1719
import java.util.stream.Collectors;
1820

1921
import static io.cucumber.core.resource.ClasspathSupport.CLASSPATH_SCHEME_PREFIX;
2022
import static io.cucumber.junit.platform.engine.Constants.ANSI_COLORS_DISABLED_PROPERTY_NAME;
2123
import static io.cucumber.junit.platform.engine.Constants.EXECUTION_DRY_RUN_PROPERTY_NAME;
24+
import static io.cucumber.junit.platform.engine.Constants.FILTER_NAME_PROPERTY_NAME;
2225
import static io.cucumber.junit.platform.engine.Constants.FILTER_TAGS_PROPERTY_NAME;
2326
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
2427
import static io.cucumber.junit.platform.engine.Constants.OBJECT_FACTORY_PROPERTY_NAME;
@@ -59,11 +62,12 @@ public boolean isWip() {
5962
return false;
6063
}
6164

62-
public Expression tagFilter() {
63-
return TagExpressionParser
64-
.parse(configurationParameters
65-
.get(FILTER_TAGS_PROPERTY_NAME)
66-
.orElse(""));
65+
Optional<Expression> tagFilter() {
66+
return configurationParameters.get(FILTER_TAGS_PROPERTY_NAME, TagExpressionParser::parse);
67+
}
68+
69+
Optional<Pattern> nameFilter() {
70+
return configurationParameters.get(FILTER_NAME_PROPERTY_NAME, Pattern::compile);
6771
}
6872

6973
@Override

0 commit comments

Comments
 (0)