Skip to content

Conversation

wang3820
Copy link

@wang3820 wang3820 commented Nov 2, 2023

Issue

The root issue is that both mockResponse.getBodyAsString and mapper.writeValueAsString use maps to convert json data into strings. In this case both strings are checked if match to determine the mockResponse has the correct content. However, because map does not guarantee the order of elements returned, the two strings could have the same content but in different order, thus the flakiness.

Fix

This flaky test has been fixed through leveraging the Jackson library, which incorporates the JsonNode and ObjectMapper classes. These components are employed for parsing two JSON strings into tree models, which are subsequently compared node by node when assertion is called.

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.

1 participant