Using @WebMvcTest will auto-configure all web layer beans by looking for a @SpringBootConfiguration class (such as @SpringBootApplication).
If the configuration class is in a different package and can't be found by scanning, can I provide it directly to @WebMvcTest?
The following will point to the correct @SpringBootApplication class:
@RunWith(SpringJUnit4ClassRunner.class)
@WebMvcTest(controllers = {MyController.class})
@ContextConfiguration(classes={MySpringBootApplicationClass.class})
public class MyControllerTest {
//...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With