简体   繁体   中英

IntelliJ runs Kotlin tests annotated with @Ignore

I have a Kotlin project that uses JUnit 5.2.0. When I use IntelliJ to run tests, it runs all tests, even those annotated with @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测试运行器

Can anyone explain to me why this might be happening?

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

Figured out the answer: JUnit5 replaces JUnit4's @Ignore with @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测试跑步者

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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