三个测试容器从哪里来?

我把一个演示JUnit5项目放在一起来试用这个框架。 该项目包括Gradle(4.4),Java(8)和Kotlin(1.2.0)四个测试用例。 我有下面的Gradle构建脚本(我已经删除了大部分的样板,只保留重要的东西):

apply plugin: 'java' apply plugin: 'kotlin' apply plugin: 'org.junit.platform.gradle.plugin' repositories { mavenCentral() } buildscript { ext.kotlin_version = '1.2.0' repositories { mavenCentral() } dependencies { classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } configurations { all { exclude group: 'junit', module: 'junit' } } project.ext { junitPlatformVersion = '1.0.2' junitJupiterVersion = '5.0.2' } dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" testCompile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" testCompile "org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}" testRuntime "org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}" } junitPlatform { platformVersion '1.0.2' filters { engines { include 'junit-jupiter' } } } 

我也有一个KotlinTest.kt和一个具有相同测试用例的JavaTest.java:

 @Test fun junit5TestPasses() { assertTrue(true) } @Test fun junit5TestFails() { assertTrue(false) } 

当我用gradlew junitPlatformTest运行我的测试时,我正确地看到2个测试通过和2个测试失败。 不过,我也看到“find3个容器”。 我的问题是为什么有3个容器find? 他们是什么? 我似乎无法find有关此方案的JUnit5用户指南中有关测试容器的直接答案。

3个容器= JUnit Jupiter Engine + KotlinTest.class + JavaTest.class

一个引擎, TestEngine的实现,也被认为是一个容器。 下一个级别是包含@Test -annotated方法的类。 看看从用户指南复制的例子:

 ├─ JUnit Vintage │ └─ example.JUnit4Tests │ └─ standardJUnit4Test ✔ └─ JUnit Jupiter ├─ StandardTests │ ├─ succeedingTest() ✔ │ └─ skippedTest() ↷ for demonstration purposes └─ A special test case ├─ Custom test name containing spaces ✔ ├─ ╯°□°)╯ ✔ └─ 😱 ✔ Test run finished after 64 ms [ 5 containers found ] [ 0 containers skipped ] [ 5 containers started ] [ 0 containers aborted ] [ 5 containers successful ] [ 0 containers failed ] [ 6 tests found ] [ 1 tests skipped ] [ 5 tests started ] [ 0 tests aborted ] [ 5 tests successful ] [ 0 tests failed ] 

在这里你看到五个容器,即:

  1. JUnit Vintage引擎
  2. example.JUnit4Tests
  3. JUnit Jupiter引擎
  4. StandardTests
  5. 一个特殊的测试用例

所有六叶都是测试。

要查看为您的测试计划运行而呈现的类似树 ,请将details 'tree'添加到Gradle junitPlatform任务。