LoginSignup
3
2

More than 5 years have passed since last update.

JUnit 5 assertAll

Last updated at Posted at 2018-12-24

JUnit 5 の導入

Gradle を使っている場合は次のように記述を加える。 Gradle 4.6 よりサポートされている。

Gradle

build.gradle
dependencies {
    testCompile("org.junit.jupiter:junit-jupiter-api:5.3.2")
    testRuntime("org.junit.jupiter:junit-jupiter-engine:5.3.2")
}

test {
    useJUnitPlatform()
}

Kotlin

build.gradle.kts
dependencies {
    testCompile("org.junit.jupiter:junit-jupiter-api:5.3.2")
    testRuntime("org.junit.jupiter:junit-jupiter-engine:5.3.2")
}

task.withType<Test> {
    useJUnitPlatform()
}

全てのチェックを全て実行する - assertAll

Java と Kotlin ではインポートする関数を変えたほうがよい。

Java
import org.junit.jupiter.api.Assertions.assertAll

assertAll(
    () -> { assertEquals(1, 1) },
    () -> { assertEquals(1, 2) }
)
Kotlin
import org.junit.jupiter.api.assertAll

assertAll(
    { assertEquals(1, 1) },
    { assertEquals(1, 2) }
)

もし Kotlin で Java と同じ関数を使うなら...

Kotlin
import org.junit.jupiter.api.Assertions.assertAll

assertAll(
    Executable { assertEquals(1, 1) },
    Executable { assertEquals(1, 2) }
)
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2