Skip to content

fix: flakiness in org.json.junit.XMLTest#testIndentComplicatedJsonObjectWithArrayAndWithConfig#797

Closed
hofi1 wants to merge 0 commit into
stleary:masterfrom
hofi1:bugfix/fix-flakyness-org.json.junit.XMLTest#testIndentComplicatedJsonObjectWithArrayAndWithConfig
Closed

fix: flakiness in org.json.junit.XMLTest#testIndentComplicatedJsonObjectWithArrayAndWithConfig#797
hofi1 wants to merge 0 commit into
stleary:masterfrom
hofi1:bugfix/fix-flakyness-org.json.junit.XMLTest#testIndentComplicatedJsonObjectWithArrayAndWithConfig

Conversation

@hofi1

@hofi1 hofi1 commented Oct 14, 2023

Copy link
Copy Markdown
Contributor

Problem:

In this test, the contents of an XML file and a JSON file are getting parsed and compared. But XML does not specify the order of the elements in the String, what means that the actual and the expected string cannot be directly compared for equality.
The flaky test was found by using the NonDex tool.

assertEquals(expected.toString(), actualString);

Solution:

To fix this assertion without the import of a new XMLAssertion library, just like in other PRs discussed, the XML String gets converted to a JSON Object and afterward compared for similarity. This is needed due to the fact that XML Objects do not offer a similarity() method.

assertTrue(XML.toJSONObject(expected.toString()).similar(XML.toJSONObject(actualString)));

Result:

The test is deterministic and not flaky. This improves the quality of the test and reduces the time to search for the bug during future development, as well as the need for reruns of the pipeline.

Reproduce

mvn edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=org.json.junit.XMLTest#testIndentComplicatedJsonObjectWithArrayAndWithConfig

@stleary

stleary commented Oct 14, 2023

Copy link
Copy Markdown
Owner

Looks like the code is out of date. Consider taking a new fork and working from there.

@hofi1 hofi1 closed this Oct 14, 2023
@hofi1 hofi1 force-pushed the bugfix/fix-flakyness-org.json.junit.XMLTest#testIndentComplicatedJsonObjectWithArrayAndWithConfig branch from f4f7fc4 to f346203 Compare October 14, 2023 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants