SpringBoot-Learning icon indicating copy to clipboard operation
SpringBoot-Learning copied to clipboard

Fix a flaky test testUserController

Open dserfe opened this issue 1 year ago • 4 comments

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.

dserfe avatar Sep 12 '23 21:09 dserfe

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

xiaofeiahaha avatar Sep 12 '23 21:09 xiaofeiahaha

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

liuhamglin avatar Sep 12 '23 21:09 liuhamglin

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

uncleCG avatar Sep 12 '23 21:09 uncleCG

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

loquitowen avatar Sep 12 '23 21:09 loquitowen