SpringRunner vs SpringBootTest

后端 未结 3 1425
时光取名叫无心
时光取名叫无心 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:38

    @RunWith is an old annotation from JUnit 4 to use test runners. If you're using JUnit 5 (Jupiter), you should use @ExtendWith to use JUnit extensions

    See https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-testing

    "If you are using JUnit 4, don’t forget to also add @RunWith(SpringRunner.class) to your test, otherwise the annotations will be ignored. If you are using JUnit 5, there’s no need to add the equivalent @ExtendWith(SpringExtension.class) as @SpringBootTest and the other @…Test annotations are already annotated with it.

提交回复
热议问题