Skip to content
Advertisement

Tag: spring-test-mvc

Why do MockMvc tests suggest injecting WebApplicationContext @BeforeEach test?

So the reference documentation suggests why not do it as constructor injection instead? (I haven’t tried this, I’m just assuming it doesn’t immediately blow up) Answer Whether you choose constructor injection, method injection, or field injection is a matter of taste when using JUnit Jupiter with the SpringExtension. The example in the reference manual simply shows one way to do

How to write a unit test for a Spring Boot Controller endpoint

I have a sample Spring Boot app with the following Boot main class Controller What’s the easiest way to write a unit test for the controller? I tried the following but it complains about failing to autowire WebApplicationContext Answer Spring MVC offers a standaloneSetup that supports testing relatively simple controllers, without the need of context. Build a MockMvc by registering

Advertisement