Home > Back-end >  How to replace annotation SpringBootTest if I have to wire up only one class, not the whole applicat
How to replace annotation SpringBootTest if I have to wire up only one class, not the whole applicat

Time:01-05

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 ?

CodePudding user response:

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

}
  •  Tags:  
  • Related