From 238071ba3f18af742021192d20d69cd1b9e8db8d Mon Sep 17 00:00:00 2001 From: manumafe98 Date: Mon, 8 Jan 2024 18:44:06 -0300 Subject: [PATCH] Adding documentation for common piftall that leads to exceptions --- README.adoc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.adoc b/README.adoc index 17dce2e..4a0f255 100644 --- a/README.adoc +++ b/README.adoc @@ -1,5 +1,7 @@ :spring_version: current :DirtiesContext: https://docs.spring.io/spring/docs/{spring_version}/javadoc-api/org/springframework/test/annotation/DirtiesContext.html +:HttpMediaTypeNotAcceptableException: https://docs.spring.io/spring-framework/docs/{spring_version}/javadoc-api/org/springframework/web/HttpMediaTypeNotAcceptableException.html +:HttpMessageNotWritableException: https://docs.spring.io/spring-framework/docs/{spring_version}/javadoc-api/org/springframework/http/converter/HttpMessageNotWritableException.html :toc: :icons: font :source-highlighter: prettify @@ -172,6 +174,12 @@ include::complete/src/test/java/com/example/testingweb/TestingWebApplicationTest ---- ==== +NOTE: When using `@SpringBootTest` with `@AutoConfigureMockMvc` you could get some exceptions +like {HttpMediaTypeNotAcceptableException}[`HttpMediaTypeNotAcceptableException`] or +{HttpMessageNotWritableException}[`HttpMessageNotWritableException`] caused by missconfigurations, +to avoid this behavoir you should use the annotation `@AutoConfigureWebMvc`or reeplace +`@AutoConfigureMockMvc` and `@AutoConfigureWebMvc` with `@WebMvcTest` that includes both functionalities. + In this test, the full Spring application context is started but without the server. We can narrow the tests to only the web layer by using `@WebMvcTest`, as the following listing (from `src/test/java/com/example/testingweb/WebLayerTest.java`) shows: