Skip to content

Testing

IDragonfire edited this page May 8, 2017 · 7 revisions

This Page is to summarize sum best practice for testing.

Compare JSON

We recommand to use Json Path. Plesae read the documentation:

https://github.com/json-path/JsonPath

Examples

.andExpect(jsonPath("$.player.id", is(player.getId())))
.andExpect(jsonPath("$.player.login", is(player.getLogin())))
.andExpect(jsonPath("$.clan", nullValue()));
.andExpect(jsonPath("$.errors", hasSize(1)))
.andExpect(jsonPath("$.errors[0].status", is(HttpStatus.UNPROCESSABLE_ENTITY.toString())))
.andExpect(jsonPath("$.errors[0].title", is("Clan Tag already in use")))
.andExpect(jsonPath("$.errors[0].detail", is("The clan tag 'My Cool ClanName' is already in use. Please choose a different clan tag.")))
.andExpect(jsonPath("$.errors[0].code", is("157")))
.andExpect(jsonPath("$.errors[0].meta.args[0]", is("My Cool ClanName")));

Sources

http://docs.spring.io/spring/docs/3.0.x/reference/testing.html

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html

https://spring.io/blog/2014/05/23/preview-spring-security-test-web-security

https://spring.io/guides/gs/testing-web/

https://dzone.com/articles/unit-and-integration-tests-in-spring-boot

Clone this wiki locally