Skip to content

Commit a0555b2

Browse files
committed
docs: document JUnit 5 parameterized test configuration for Gradle
Gradle's JUnit XML reporter writes display-name-only test case names ([N] args) that omit the method name, preventing reqstool from linking parameterized test results to @SVCs-annotated methods. Document the one-line fix (systemProperty on tasks.withType(Test)) and note the limitation for explicit name="{index}..." annotations. Signed-off-by: Jimisola Laursen <jimisola@jimisola.com>
1 parent f901f7c commit a0555b2

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,34 @@ requirementsTool {
6969
}
7070
```
7171

72+
## JUnit 5 parameterized tests
73+
74+
Gradle's JUnit XML reporter writes test case names using the parameterized test's display name.
75+
By default this is `[N] arguments` — a format that omits the method name.
76+
Reqstool cannot link these entries to `@SVCs`-annotated methods without the method name.
77+
78+
Add this to your build to include the method name in every test case name, covering all test tasks (unit, integration, e2e):
79+
80+
```groovy
81+
tasks.withType(Test).configureEach {
82+
systemProperty 'junit.jupiter.params.displayname.default', '{displayName}[{index}]'
83+
}
84+
```
85+
86+
Kotlin DSL:
87+
88+
```kotlin
89+
tasks.withType<Test>().configureEach {
90+
systemProperty("junit.jupiter.params.displayname.default", "{displayName}[{index}]")
91+
}
92+
```
93+
94+
This produces names like `checkStatus(StatusType)[1]` instead of `[1] ACTIVE`, which reqstool can correctly attribute to the annotated method.
95+
96+
> **Note:** Tests with an explicit `@ParameterizedTest(name = "{index} ...")` still omit the method name because the explicit value overrides the default. Either remove the custom `name` or change it to start with `{displayName}`: `@ParameterizedTest(name = "{displayName}[{index}] ...")`.
97+
98+
Maven Surefire always embeds the method name regardless of display-name settings — no change needed for Maven projects.
99+
72100
## Task reference
73101

74102
### `assembleRequirements`

‎docs/modules/ROOT/pages/configuration.adoc‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,44 @@ requirementsTool {
122122
}
123123
----
124124

125+
[[parameterized-tests]]
126+
== JUnit 5 parameterized tests
127+
128+
Gradle's JUnit XML reporter writes test case names using the parameterized test's display name.
129+
By default this is `[N] arguments` -- a format that omits the method name.
130+
Reqstool cannot link these entries to `@SVCs`-annotated methods without the method name.
131+
132+
Add the following to your build to make the method name part of every test case name, across
133+
all test tasks (unit, integration, e2e):
134+
135+
[source,gradle]
136+
----
137+
tasks.withType(Test).configureEach {
138+
systemProperty 'junit.jupiter.params.displayname.default', '{displayName}[{index}]'
139+
}
140+
----
141+
142+
Kotlin DSL:
143+
144+
[source,kotlin]
145+
----
146+
tasks.withType<Test>().configureEach {
147+
systemProperty("junit.jupiter.params.displayname.default", "{displayName}[{index}]")
148+
}
149+
----
150+
151+
This changes the default display name for every `@ParameterizedTest` that does not have an
152+
explicit `name =` attribute, producing names like `checkStatus(StatusType)[1]` instead of
153+
`[1] ACTIVE`.
154+
155+
NOTE: Tests that use an explicit `@ParameterizedTest(name = "{index} ...")` still omit the
156+
method name because the explicit value overrides the default.
157+
Either remove the custom `name` or change it to begin with `{displayName}`:
158+
`@ParameterizedTest(name = "{displayName}[{index}] ...")`.
159+
160+
Maven Surefire is unaffected -- it always embeds the method name regardless of display-name
161+
settings, so no configuration change is required for Maven projects.
162+
125163
== Auto-wired task dependencies
126164

127165
When the `java` plugin is applied, the plugin automatically wires:

0 commit comments

Comments
 (0)