何时使用@RunWith,何时使用@ExtendWith [英] When to use @RunWith and when @ExtendWith

查看:47
本文介绍了何时使用@RunWith,何时使用@ExtendWith的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和我的团队一直在使用 Spring Boot 开发一系列微服务.由于服务经历了 JUnit 和 Spring Boot 升级(我们现在使用的是 Spring Boot 2 和 JUnit 5),不同开发人员实现的不同 JUnit 现在使用不同的模式:

My team and I have been working on a bunch of microservices using Spring boot. Since the services went through JUnit and Spring Boot upgrades (We're using now Spring Boot 2 and JUnit 5), different JUnit implemented by different devs, are now using different patterns with:

  • @ExtendWith
  • @RunWith

今天这两者之间有什么区别,我们真的需要它们用于我们的单元测试还是嵌入到一些新的 Spring Boot 注释中?

Today what's the difference between the two of them and do we really need them for our Unit Tests or are embedded in some new Spring Boot annotation?

推荐答案

答案可以在文档:

如果您使用的是 JUnit 4,请不要忘记将 @RunWith(SpringRunner.class) 添加到您的测试中,否则注释将被忽略.如果您使用的是 JUnit 5,则无需添加等效的@ExtendWith(SpringExtension.class) 作为@SpringBootTest 和其他@…Testannotations 已经用它进行了注释

If you are using JUnit 4, don’t forget to 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 @…Testannotations are already annotated with it

.

这篇关于何时使用@RunWith,何时使用@ExtendWith的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆