Skip to content

Restore original SetSystemProperty values in a ParameterizedTest#5720

Open
mpkorstanje wants to merge 9 commits into
mainfrom
rien/create-single-incremental-backup-per-context
Open

Restore original SetSystemProperty values in a ParameterizedTest#5720
mpkorstanje wants to merge 9 commits into
mainfrom
rien/create-single-incremental-backup-per-context

Conversation

@mpkorstanje
Copy link
Copy Markdown
Member

@mpkorstanje mpkorstanje commented Jun 1, 2026

Restore original SetSystemProperty values in a ParameterizedTest

The system properties extension would for each context and all its
ancestors process the system property annotations. After applying each
context it would also create an incremental backup. But it would only
store the latest backup.

This is a problem when parametrized tests are used. The ancestral
context includes the test method element twice:

0 = {Optional@5653} "Optional[void RestoreAfterParameterizedTest.testParamWithoutRestore(int)]"
1 = {Optional@5654} "Optional[void RestoreAfterParameterizedTest.testParamWithoutRestore(int)]"
2 = {Optional@5655} "Optional[class SystemPropertiesExtensionTests$RestoreAfterParameterizedTest]"
3 = {Optional@5656} "Optional[class SystemPropertiesExtensionTests]"
4 = {Optional@4689} "Optional.empty"

As such the system property will be backed up, modified, the modified
value will be backed up again and then modified (idempotent). Because
only the last incremental backup is stored, the original value is
never restored.

This could be solved by either:

a) Only processing the original context and none of its ancestors.
b) Using a compound key of the original context and its current ancestor.

Option a mostly works, but will not properly restore programmatically
modified keys when nested tests are sparsely annotated. So it must be
option b.

Fixes: #5717
Supersedes: #5718


I hereby agree to the terms of the JUnit Contributor License Agreement.


Definition of Done

nielsbasjes and others added 6 commits June 1, 2026 10:03
Signed-off-by: Niels Basjes <niels@basjes.nl>
The system properties extension would for each context and all its
ancestors process the system property annotations. After applying each
context it would also create an incremental backup. But it would only
store the latest backup.

This is a problem when parametrized tests are used. The ancestral
context includes the test method element twice:

```
0 = {Optional@5653} "Optional[void RestoreAfterParameterizedTest.testParamWithoutRestore(int)]"
1 = {Optional@5654} "Optional[void RestoreAfterParameterizedTest.testParamWithoutRestore(int)]"
2 = {Optional@5655} "Optional[class SystemPropertiesExtensionTests$RestoreAfterParameterizedTest]"
3 = {Optional@5656} "Optional[class SystemPropertiesExtensionTests]"
4 = {Optional@4689} "Optional.empty"
 ```

As such the system  property will be backed up, modified, the modified
value will be backed up again and then modified (idempotent). Because
only the last incremental backup is stored, the original value is
never restored.

This could be solved by either:

 a) Only processing the current context and none of its ancestors.
 b) Using a compound key of the current context and its ancestors.

Option a mostly works, but will not properly restore programmatically
modified keys when nested tests are sparsely annotated. So it must be
option b.
@mpkorstanje mpkorstanje changed the title Rien/create single incremental backup per context Restore original SetSystemProperty values in a ParameterizedTest Jun 1, 2026
@mpkorstanje mpkorstanje marked this pull request as ready for review June 1, 2026 23:12
@testlens-app
Copy link
Copy Markdown

testlens-app Bot commented Jun 1, 2026

✅ All tests passed ✅

🏷️ Commit: e0dd700
▶️ Tests: 7623 executed
⚪️ Checks: 16/16 completed


Learn more about TestLens at testlens.app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using @SetSystemProperty in a @ParameterizedTest fails to restore original values

2 participants