Restore original SetSystemProperty values in a ParameterizedTest#5720
Open
mpkorstanje wants to merge 9 commits into
Open
Restore original SetSystemProperty values in a ParameterizedTest#5720mpkorstanje wants to merge 9 commits into
mpkorstanje wants to merge 9 commits into
Conversation
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.
✅ All tests passed ✅🏷️ Commit: e0dd700 Learn more about TestLens at testlens.app. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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
@APIannotations