【问题标题】:IntelliJ runs Kotlin tests annotated with @IgnoreIntelliJ 运行使用 @Ignore 注释的 Kotlin 测试
【发布时间】:2019-02-25 22:38:33
【问题描述】:

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

谁能向我解释为什么会发生这种情况?

【问题讨论】:

    标签: java maven intellij-idea kotlin junit5


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2018-09-20
        • 2016-03-08
        • 2016-02-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多