dyc87112 / SpringBoot-Learning

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

Removing flakiness using .json() to check JSON string responses #96

Open akshathphillips opened 1 year ago

akshathphillips commented 1 year ago

What is the purpose of this PR

Why the tests fail

Reproduce the test failure

Expected results

Actual Result

We get the following failure for test com.didispace.chapter21.Chapter21ApplicationTests

[ERROR] Failures: 
[ERROR]   Chapter21ApplicationTests.testUserController:52 Response content
Expected: "[{\"id\":1,\"name\":\"测试大师\",\"age\":20}]"
     but: was "[{\"age\":20,\"id\":1,\"name\":\"测试大师\"}]"

Fix

For test com.didispace.chapter21.Chapter21ApplicationTests - Parse the expected and actual strings as JSON and assert the two are "similar" - i.e. they contain the same attribute-value pairs regardless of formatting with a lenient checking. The .json(), does a lenient checking on the fields, which solves this issue.

xiaofeiahaha commented 1 year ago

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

liuhamglin commented 1 year ago

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

loquitowen commented 1 year ago

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

akshathphillips commented 1 year ago

Hello. Any updates on this?