Skip to content

Conversation

@dserfe
Copy link

@dserfe dserfe commented Sep 12, 2023

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:

  1. To reproduce test failures:
  • Run the following cmds:
 mvn edu.illinois:nondex-maven-plugin:2.1.1:nondex -pl 2.x/chapter2-1 -Dtest=com.didispace.chapter21.Chapter21ApplicationTests#testUserController -DnondexRuns=10
  • Then we'll get failures:
Chapter21ApplicationTests.testUserController:52 Response content
Expected: "[{\"id\":1,\"name\":\"测试大师\",\"age\":20}]" but: was "[{\"age\":20,\"name\":\"测试大师\",\"id\":1}]"
  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.

  2. Fix:
    Use json() to compare Json objects instead of converting them to string.

@xiaofeiahaha
Copy link

xiaofeiahaha commented Sep 12, 2023 via email

@liuhamglin
Copy link

liuhamglin commented Sep 12, 2023 via email

@uncleCG
Copy link

uncleCG commented Sep 12, 2023 via email

@loquitowen
Copy link

loquitowen commented Sep 12, 2023 via email

@dserfe dserfe closed this by deleting the head repository Mar 10, 2025
@uncleCG
Copy link

uncleCG commented Mar 10, 2025 via email

@liuhamglin
Copy link

liuhamglin commented Mar 10, 2025 via email

@xiaofeiahaha
Copy link

xiaofeiahaha commented Mar 10, 2025 via email

@loquitowen
Copy link

loquitowen commented Mar 10, 2025 via email

@NeoYeK
Copy link

NeoYeK commented Mar 10, 2025 via email

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.

6 participants