IntelliJ运行带有@Ignore注释的Kotlin测试

Ade*_*erd 1 java intellij-idea maven kotlin junit5

我有一个使用JUnit 5.2.0的Kotlin项目。当我使用IntelliJ运行测试时,它会运行所有测试,甚至包括带有注释的测试@org.junit.Ignore

package my.package

import org.junit.Ignore
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class ExampleTests {

    @Test fun runMe() {
        assertEquals(1, 1)
    }

    @Test @Ignore fun dontRunMe() {
        assertEquals(1, 0)
    }
}
Run Code Online (Sandbox Code Playgroud)

IntelliJ测试运行器

谁能向我解释为什么会这样?

ams*_*ger 6

在JUnit 5中,您需要为此使用@Disabled注释。


Ade*_*erd 5

找出答案:JUnit5 将 JUnit4 替换@Ignore@Disabled.

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test

class ExampleTests {

    @Test fun runMe() {
        assertEquals(1, 1)
    }

    @Test @Disabled fun dontRunMe() {
        assertEquals(1, 0)
    }
}
Run Code Online (Sandbox Code Playgroud)

IDEA 测试运行器