Test Fix: Resolve unintended test failures caused by non-deterministic ordering of elements in the serialized XML output #681
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.
Due to the non-deterministic behavior of serialized XML output, the order of items in the class can vary. This may lead to an AssertionError when comparing an item object with its expected value.
The example below shows a failure under NonDex on line 54
Click on to see more details on the error message when running each test
To reproduce each, run these at the root directory:
(Note: The failing test might not be seen if every test happens to have the item objects in the expected order. Try running it several times or increase the the number of runs with -DnondexRuns= to reproduce the issue.)
The log output can be found here for your reference:
mvn-nondex-1730966644.log
To resolve this, we can annotate the fields in the Item class to enforce a specific order.
After applying the fix, the test should now pass with NonDex as expected:
The log file showing the test passing after the fix can be found here:
mvn-nondex-fix-1730968323.log
Please let me know if this approach works for you. If not, I'm happy to discuss alternatives and am willing to spend more time to address the test in the way you'd prefer. Thank you!