blade icon indicating copy to clipboard operation
blade copied to clipboard

Fixed test failure(test4) by comparing maps instead of json.

Open RugvedB opened this issue 1 year ago • 0 comments

Created this PR to fix 1 flaky test - test4


  1. How were these test identified as flaky? This test was identified as flaky by using an open-source research tool named NonDex which is responsible for finding and diagnosing non-deterministic runtime exceptions in Java programs.

  2. What was the error? When the test convert childBean to json string String json = JsonKit.toString(childBean);, the order of keys (i.e. repeatField, childField, superField) is not guaranteed. Thus, when we compare this String variable 'json' directly to hardcoded string "{\"repeatField\":\"sss\",\"childField\":\"child\",\"superField\":\"super\"}", it may fail sometimes because the order could be different than the expected order i.e repeatField, childField, superField.

Error:

[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.024 s <<< FAILURE! -- in com.hellokaton.blade.kit.JsonKitTest
[ERROR] com.hellokaton.blade.kit.JsonKitTest.test4 -- Time elapsed: 0.022 s <<< FAILURE!
org.junit.ComparisonFailure: expected:<{"[repeatField":"sss","childField":"child]","superField":"supe...> but was:<{"[childField":"child","repeatField":"sss]","superField":"supe...>
  1. What is the fix? Instead of comparing json strings, we can convert json to Map and then compare the maps. This PR proposes to compare Maps instead of json strings in test4.

You can run the following commands to run test4 using NonDex tool:

mvn -pl blade-kit edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=com.hellokaton.blade.kit.JsonKitTest#test4

Test Environment:

java version 11.0.19
Apache Maven 3.9.5

Kindly let me know if this fix is acceptable. Thank you

RugvedB avatar Nov 28 '23 05:11 RugvedB