dyc87112 / SpringBoot-Learning

《Spring Boot基础教程》,2.x版本持续连载中!点击下方链接直达教程目录!
https://blog.didispace.com/spring-boot-learning-2x/
15.74k stars 4.88k forks source link

Fix a flaky test testUserController #98

Open dserfe opened 1 year ago

dserfe commented 1 year ago

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}]"
  2. 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.

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

xiaofeiahaha commented 1 year ago

您好!我已收到的您的来信,并会尽早查收。————————————————————                                                葛晓飞

liuhamglin commented 1 year ago

这是一封自动回复邮件。已经收到您的来信,我会尽快回复。

uncleCG commented 1 year ago

这是来自QQ邮箱的假期自动回复邮件。您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

loquitowen commented 1 year ago

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。