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…
Tag: spring-test-mvc
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…