繁体   English   中英

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

[英]IntelliJ runs Kotlin tests annotated with @Ignore

我有一个使用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)
    }
}

IntelliJ测试运行器

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

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

找出答案: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)
    }
}

IDEA测试跑步者

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM