Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a flaky test testUserController #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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

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.

5 participants