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 {
//...
}