SpringRunner vs SpringBootTest

后端 未结 3 1421
时光取名叫无心
时光取名叫无心 2020-12-08 09:45

In unit test, what are the differences between @Runwith(SpringRunner.class) & @SpringBootTest?

Can you explain to me the use cases of

3条回答
  •  眼角桃花
    2020-12-08 10:24

    From spring.io :

    @RunWith(SpringRunner.class) tells JUnit to run using Spring’s testing support. SpringRunner is the new name for SpringJUnit4ClassRunner, it’s just a bit easier on the eye.

    @SpringBootTest is saying “bootstrap with Spring Boot’s support” (e.g. load application.properties and give me all the Spring Boot goodness)

    So if you don't need everything that Spring Boot loads for your integration test, you may not need @SpringBootTest

提交回复
热议问题