Skip to content

Commit a2f0791

Browse files
authored
[JUnit Platform Engine] Accept partial matches in name filter (#3174)
In 'CucumberTestDescriptor', 'cucumber.filter.name' was evaluated using 'matches()'which requires the pattern to cover the full scenario name. Replaced with 'find()' to align with 'NamePredicate' used by JUnit 4 and CLI. Fixes #3166. Non-anchored patterns like 'Cool test' now correctly match any scenario whose name contains that substring, consistent with JUnit 4 and the CLI.
1 parent 3f5970c commit a2f0791

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
### Added
1414
- [Java] Add optional names to `@Before`, `@After`, `@BeforeStep` and `@AfterStep` hooks and emit hook names in messages ([#2917](https://github.com/cucumber/cucumber-jvm/issues/2917), [#3173](https://github.com/cucumber/cucumber-jvm/pull/3173))
1515

16+
### Fixed
17+
- [JUnit Platform Engine] Accept partial matches with `cucumber.filter.name` and align the behavior with JUnit 4 and CLI ([#3174](https://github.com/cucumber/cucumber-jvm/pull/3174))
18+
1619
### Changed
1720
- [All] Set baseline to Java 17 ([#3116](https://github.com/cucumber/cucumber-jvm/pull/3116))
1821
- [All] Adopt [JSpecify](https://jspecify.dev/) to declare nullability ([#3116](https://github.com/cucumber/cucumber-jvm/pull/3116))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ private Optional<SkipResult> shouldBeSkippedByTagFilter(CucumberEngineExecutionC
292292

293293
private Optional<SkipResult> shouldBeSkippedByNameFilter(CucumberEngineExecutionContext context) {
294294
return context.getConfiguration().nameFilter().map(pattern -> {
295-
if (pattern.matcher(pickle.getName()).matches()) {
295+
if (pattern.matcher(pickle.getName()).find()) {
296296
return SkipResult.doNotSkip();
297297
}
298298
return SkipResult

cucumber-junit-platform-engine/src/test/java/io/cucumber/junit/platform/engine/CucumberTestEngineTest.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,51 @@ void selectAndSkipDisabledScenarioByName() {
690690
event(skippedWithReason("'cucumber.filter.name=^Nothing$' did not match this scenario"))));
691691
}
692692

693+
@Test
694+
void anchoredNamePatternMatchesExactName() {
695+
EngineTestKit.engine(ENGINE_ID)
696+
.configurationParameter(FILTER_NAME_PROPERTY_NAME, "^A single scenario$")
697+
.selectors(selectFile("src/test/resources/io/cucumber/junit/platform/engine/single.feature"))
698+
.execute()
699+
.testEvents()
700+
.assertThatEvents()
701+
.haveExactly(1, event(test(), finishedSuccessfully()));
702+
}
703+
704+
@Test
705+
void anchoredNamePatternDoesNotMatchPartOfName() {
706+
EngineTestKit.engine(ENGINE_ID)
707+
.configurationParameter(FILTER_NAME_PROPERTY_NAME, "^A single$")
708+
.selectors(selectFile("src/test/resources/io/cucumber/junit/platform/engine/single.feature"))
709+
.execute()
710+
.testEvents()
711+
.assertThatEvents()
712+
.haveExactly(1, event(test(),
713+
event(skippedWithReason("'cucumber.filter.name=^A single$' did not match this scenario"))));
714+
}
715+
716+
@Test
717+
void nonAnchoredNamePatternMatchesPartOfName() {
718+
EngineTestKit.engine(ENGINE_ID)
719+
.configurationParameter(FILTER_NAME_PROPERTY_NAME, "single")
720+
.selectors(selectFile("src/test/resources/io/cucumber/junit/platform/engine/single.feature"))
721+
.execute()
722+
.testEvents()
723+
.assertThatEvents()
724+
.haveExactly(1, event(test(), finishedSuccessfully()));
725+
}
726+
727+
@Test
728+
void wildcardNamePatternMatchesPartOfName() {
729+
EngineTestKit.engine(ENGINE_ID)
730+
.configurationParameter(FILTER_NAME_PROPERTY_NAME, "single .*")
731+
.selectors(selectFile("src/test/resources/io/cucumber/junit/platform/engine/single.feature"))
732+
.execute()
733+
.testEvents()
734+
.assertThatEvents()
735+
.haveExactly(1, event(test(), finishedSuccessfully()));
736+
}
737+
693738
@Test
694739
void cucumberTagsAreConvertedToJunitTags() {
695740
EngineTestKit.engine(ENGINE_ID)

0 commit comments

Comments
 (0)