本文介绍了junit-jupiter-api 和 junit-jupiter-engine 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

maven 模块 junit-jupiter-apijunit-jupiter-engine 有什么区别?是否有必要在 build.gradle 中包含这两个依赖项?

What's the difference between maven modules junit-jupiter-api and junit-jupiter-engine? Is it necessary to include both dependencies in build.gradle?

我需要同时提供这两个依赖项吗?

Do I need to provide both dependencies?

testCompile("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
testCompile("org.junit.jupiter:junit-jupiter-api:${junitVersion}")

还是只有一个依赖就足够了?

Or only one dependency is enough?

testCompile("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")

我是否需要添加对 junit-vintage-engine 的依赖?

And do I need to add a dependency on junit-vintage-engine?

推荐答案

JUnit 5.4 之前的版本

来自文档:

junit-jupiter-api

用于编写测试和扩展的 JUnit Jupiter API.

JUnit Jupiter API for writing tests and extensions.

junit-jupiter-engine

JUnit Jupiter 测试引擎实现,仅在运行时需要.

JUnit Jupiter test engine implementation, only required at runtime.

junit-vintage-engine

JUnit Vintage 测试引擎实现,允许在新的 JUnit 平台上运行复古 JUnit 测试,即以 JUnit 3 或 JUnit 4 风格编写的测试.

JUnit Vintage test engine implementation that allows to run vintage JUnit tests, i.e. tests written in the JUnit 3 or JUnit 4 style, on the new JUnit Platform.

所以……

  • 您需要 junit-jupiter-apijunit-jupiter-engine 来编写和运行 JUnit5 测试
  • 您只需要 junit-vintage-engine 如果 (a) 您使用 JUnit5 (b) 您的测试用例使用 JUnit4 构造/注释/规则等
  • You need both junit-jupiter-api and junit-jupiter-engine to write and run JUnit5 tests
  • You only need junit-vintage-engine if (a) you are running with JUnit5 and (b) your test cases use JUnit4 constructs/annotations/rules etc

在 JUnit 5.4 中,这被简化,请参阅此答案了解更多详情.

In JUnit 5.4 this is simplified, see this answer for more details.

这篇关于junit-jupiter-api 和 junit-jupiter-engine 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-20 07:40