junit5-gradle-consumerを参考にするとさくっとGradleで実行できるようになる。
build.gradle
JUnit Platform Gradle Pluginを設定して、testRuntimeにjunit-jupiter-engineを追加してあげる必要がる。
buildscript { repositories { mavenCentral() } dependencies { classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0' } } apply plugin: 'org.junit.platform.gradle.plugin' dependencies { testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.0' testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.0.0' }
テストの実行
テストを実行するとこんな感じに結果が表示される。
残念ながらGradleさんのtest reportには対応していないみたいでhtmlは保存されないみたい。
なお、テスト結果のxmlは出力されるので、JUnit4の時と同じようにCIでは結果を集計できる。
➜ junit5-sample ./gradlew clean test > Task :compileTestKotlin Using kotlin incremental compilation > Task :junitPlatformTest Test run finished after 139 ms [ 5 containers found ] [ 0 containers skipped ] [ 5 containers started ] [ 0 containers aborted ] [ 5 containers successful ] [ 0 containers failed ] [ 4 tests found ] [ 0 tests skipped ] [ 4 tests started ] [ 0 tests aborted ] [ 4 tests successful ] [ 0 tests failed ] BUILD SUCCESSFUL in 1s
おわり。