Search code examples
springspring-bootspring-mvcspring-boot-test

How to replace annotation SpringBootTest if I have to wire up only one class, not the whole application


I know if we use annotation @SpringBootTest, we wire up whole application.

But if I need to run just this class without launching the whole app, how can I replace @SpringBootTest ?


Solution

  • I use @ContextConfiguration(classes = ClassThatYouAreGoingToTest.class)

    @RunWith(SpringRunner.class)
    @ContextConfiguration(classes = ClassThatYouAreGoingToTest.class)
    public class TestClass{
        @MockBean
        private BeanUsedInYourTestClass beanUsedInYourTestSubject;
        .....///another mock bean if required
        @Autowired
        private ClassThayYouAreGoingToTest testSubject;
       
    ///your @Tests
    
    }