JUnit5中是否已弃用测试套件? [英] Are test suites considered deprecated in JUnit5?

查看:435
本文介绍了JUnit5中是否已弃用测试套件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JUnit5创建测试套件.经过一番研究,我无法断定它是否是受支持的功能.

I am trying to create test suites with JUnit5. After some research I was not able to conclude whether it is a supported feature or not.

官方用户指南仅提及了与JUnit 4的向后兼容性有关的套件.

The official user guide only mentions suites with regard to backwards compatibility to JUnit 4.

这是在JUnit 4中完成的过程:

This is how it was done back in JUnit 4:

@RunWith(Suite.class)
@SuiteClasses({Test1.class, Test2.class})
public class TestSuite {
}

这是否意味着测试套件现在已被弃用,还是相同的概念仍可以使用另一个名称?

Does this mean, that Test Suites are considered deprecated now, or is the same concept still available under another name?

推荐答案

这是否意味着测试套件现在已被弃用,还是同一概念仍可以使用其他名称?

Does this mean, that Test Suites are considered deprecated now, or is the same concept still available under another name?

苦涩的套房答案:

Bitter Suite Answer:

事实上,JUnit 5中对测试套件提供了支持,但是几乎可以肯定这不是您想要的.但是,JUnit团队正在努力进行可能满足您需求的事情.

There is in fact support for test suites in JUnit 5, but it's almost certainly not what you're looking for. However, the JUnit Team is working on something that will likely suit your needs.

详细答案:

从JUnit 5.2开始,对 suites 的唯一内置支持是通过JUnitPlatform Runner (通过@RunWith(JUnitPlatform.class)注册的).该运行程序实际上启动了JUnit平台(也称为JUnit 5基础结构),并允许您针对各种编程模型(例如JUnit 4和JUnit Jupiter)执行测试.它还允许您选择各种内容(例如,类,程序包等),并配置包含和排除过滤器(例如,用于标记或测试引擎).

As of JUnit 5.2, the only built-in support for suites is via the JUnitPlatform Runner (registered via @RunWith(JUnitPlatform.class)). That runner actually launches the JUnit Platform (a.k.a., JUnit 5 infrastructure) and allows you to execute tests against various programming models such as JUnit 4 and JUnit Jupiter. It also allows you to select various things (e.g., classes, packages, etc.) and configure include and exclude filters (e.g., for tags or test engines).

运行程序的问题是它不能不能直接在JUnit Platform上执行.它只能 单独使用JUnit 4执行.这意味着您将失去JUnit Platform的全部报告功能,因为从JUnit Platform到JUnit 4的转换中会丢失信息.

The problem with the runner is that it can not be executed directly on the JUnit Platform. It can only be executed using JUnit 4 by itself. That means that you lose the full reporting capabilities of the JUnit Platform since information is lost in translation from the JUnit Platform to JUnit 4.

总而言之,从技术上讲,您可以使用JUnitPlatform运行程序通过JUnit 5执行套件,测试将执行,但是在IDE中的报告和显示将不是最佳选择.

In summary, you can technically use the JUnitPlatform runner to execute a suite using JUnit 5, and the tests will execute, but the reporting and display in an IDE will be suboptimal.

从好的方面来看,JUnit团队计划为JUnit 5中的套件提供内置支持,这些套件不会受到JUnit 4的JUnitPlatform运行器的缺点的困扰.有关详细信息,请参见分配给<上的a href ="https://github.com/junit-team/junit5/labels/theme%3A%20suites" rel ="noreferrer">"suites"标签.

On the bright side, the JUnit Team plans to provide built-in support for suites in JUnit 5 that does not suffer from the shortcomings of the JUnitPlatform runner for JUnit 4. For details, see all issues assigned to the "suites" label on GitHub.

此外,已经有一个功能分支您可以查看通过JitPack 消耗在Maven或Gradle构建中的哪个.

In addition, there is already a feature branch that you can check out which can be consumed in a Maven or Gradle build via JitPack.

此致

Sam(JUnit 5核心提交者)

Sam (JUnit 5 core committer)

这篇关于JUnit5中是否已弃用测试套件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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