三个测试容器从哪里来?

var*_*der 4 java kotlin junit5

我整理了一个演示JUnit5项目来试用该框架。该项目由Gradle(4.4),Java(8)和Kotlin(1.2.0)组成,并带有4个测试用例。我有以下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'
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我也有KotlinTest.kt和JavaTest.java,它们具有等效的测试用例:

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

@Test
fun junit5TestFails() {
    assertTrue(false)
}
Run Code Online (Sandbox Code Playgroud)

使用进行测试时gradlew junitPlatformTest,我正确地看到2个测试通过和2个测试失败。但是,我也看到“找到3个容器”。我的问题是为什么找到3个容器?这些是什么?在这种情况下的JUnit5用户指南中,我似乎找不到关于测试容器的直接答案。

Sor*_*ras 5

3 containers = JUnit Jupiter Engine + KotlinTest.class + JavaTest.class

An engine, an implementation of TestEngine, is also considered being a container. Next level is the class containing @Test-annotated methods. Look at the example copied from the user-guide:

?? 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          ]
Run Code Online (Sandbox Code Playgroud)

Here you see five containers, namely:

  1. JUnit Vintage engine
  2. example.JUnit4Tests class
  3. JUnit Jupiter engine
  4. StandardTests class
  5. A special test case class

All six leaves are tests.

To see a similar tree rendered for your test plan run, add details 'tree' to the Gradle junitPlatform task.