Title: fix: flakiness in org.json.junit.JSONObjectTest#valueToString by hofi1 · Pull Request #2 · hofi1/JSON-java · GitHub
Open Graph Title: fix: flakiness in org.json.junit.JSONObjectTest#valueToString by hofi1 · Pull Request #2 · hofi1/JSON-java
X Title: fix: flakiness in org.json.junit.JSONObjectTest#valueToString by hofi1 · Pull Request #2 · hofi1/JSON-java
Description: Problem: The string in the assertion can change, because the Map which is used to store the data in the JSONObject returns the data in non-deterministic order (the order of child elements in JSON strings do not matter, and JSON strings are equal regardless of the ordering of the elements on the same hierarchy level) The flaky test was found by using the NonDex tool. The flakiness was discovered on the following lines JSON-java/src/test/java/org/json/junit/JSONObjectTest.java Lines 2028 to 2029 in 01727fd assertTrue("jsonObject valueToString() incorrect", JSONObject.valueToString(jsonObject).equals(jsonObject.toString())); as well as JSON-java/src/test/java/org/json/junit/JSONObjectTest.java Lines 2039 to 2040 in 01727fd assertTrue("map valueToString() incorrect", jsonObject.toString().equals(JSONObject.valueToString(map))); Solution: Changed the assert statement from a JUnit Assertion to a JSON Assertion, so the strings are not compared charwise but are compared the way as specified for JSON strings (not taking care of the order of the elements on the same level). The JSONAssertion library was chosen because it provides general assertions to compare JSON strings without the need of writing complex JUnit Assertions, what would need a lot of work to convert the strings in a different data structure, a lot of boilerplate code as well as the chance of adding more errors than fixing. 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. Reproduce: mvn edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=org.json.junit.JSONObjectTest#valueToString
Open Graph Description: Problem: The string in the assertion can change, because the Map which is used to store the data in the JSONObject returns the data in non-deterministic order (the order of child elements in JSON ...
X Description: Problem: The string in the assertion can change, because the Map which is used to store the data in the JSONObject returns the data in non-deterministic order (the order of child elements in JSON ...
Opengraph URL: https://github.com/hofi1/JSON-java/pull/2
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:7d613c64-2dcc-c368-65dc-42415051f6f0 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D790:161EE9:1744104:2085C80:6A61C90C |
| html-safe-nonce | 00d856a3ee7224cdf4c50b28fb2f768c39f716b49b1647a58276c533e3cf98ae |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzkwOjE2MUVFOToxNzQ0MTA0OjIwODVDODA6NkE2MUM5MEMiLCJ2aXNpdG9yX2lkIjoiNjQ1ODU4NzYyMzI0NzE2OTgwNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f09f18930e2424d65c22706019b071ddb7f156a03c58b2fd881f4134495a3169 |
| hovercard-subject-tag | pull_request:1521883626 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/hofi1/JSON-java/pull/2/files |
| twitter:image | https://avatars.githubusercontent.com/u/61789910?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/61789910?s=400&v=4 |
| og:image:alt | Problem: The string in the assertion can change, because the Map which is used to store the data in the JSONObject returns the data in non-deterministic order (the order of child elements in JSON ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6f4633bcf01c1ad14b73fd07dd39ac31d61f3d3c2578ee08ec1792b7b351eeb9 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/hofi1/JSON-java git https://github.com/hofi1/JSON-java.git |
| octolytics-dimension-user_id | 61789910 |
| octolytics-dimension-user_login | hofi1 |
| octolytics-dimension-repository_id | 693387470 |
| octolytics-dimension-repository_nwo | hofi1/JSON-java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | true |
| octolytics-dimension-repository_parent_id | 1187853 |
| octolytics-dimension-repository_parent_nwo | stleary/JSON-java |
| octolytics-dimension-repository_network_root_id | 1187853 |
| octolytics-dimension-repository_network_root_nwo | stleary/JSON-java |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ac296ae7f21856f1f92adbad22f870b6fbb4b907 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width