This PR is to fix a flaky test com.didispace.chapter21.Chapter21ApplicationTests#testUserController in module 2.x/chapter2-1, we found it when using the latest version of SpringBoot-Learning:
Chapter21ApplicationTests.testUserController:52 Response content
Expected: "[{\"id\":1,\"name\":\"测试大师\",\"age\":20}]" but: was "[{\"age\":20,\"name\":\"测试大师\",\"id\":1}]"
Why it fails:
Line 52 of 2.x/chapter2-1/src/test/java/com/didispace/chapter21/Chapter21ApplicationTests.java converts a JSON object to a string. Note that this conversion does not guarantee the order of the elements.
Fix:
Use json() to compare Json objects instead of converting them to string.
This PR is to fix a flaky test
com.didispace.chapter21.Chapter21ApplicationTests#testUserController
in module2.x/chapter2-1
, we found it when using the latest version of SpringBoot-Learning:To reproduce test failures:
Why it fails: Line 52 of
2.x/chapter2-1/src/test/java/com/didispace/chapter21/Chapter21ApplicationTests.java
converts a JSON object to a string. Note that this conversion does not guarantee the order of the elements.Fix: Use
json()
to compare Json objects instead of converting them to string.