Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying @SpringBootApplication in @WebMvcTest

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?

like image 602
NatFar Avatar asked Oct 23 '25 10:10

NatFar


1 Answers

The following will point to the correct @SpringBootApplication class:

@RunWith(SpringJUnit4ClassRunner.class)
@WebMvcTest(controllers = {MyController.class})
@ContextConfiguration(classes={MySpringBootApplicationClass.class})
public class MyControllerTest {
    //...
}
like image 124
NatFar Avatar answered Oct 26 '25 01:10

NatFar