首页 > 解决方案 > 创建新的 Kotlin 控制台并创建测试让 ID 为“junit-jupiter”的 TestEngine 无法发现测试

问题描述

创建新的 Kotlin 控制台应用程序

使用构建系统 IntelliJ Project SDK java1.8 和测试框架 JUnit5。目标 JVM 1.8

有什么想法可以解决吗?

并创建一个测试。

import org.junit.jupiter.api.Test

import org.junit.jupiter.api.Assertions.*

internal class SparseVectorTest {

    @Test
    fun dotProductCase1() {
        val v1 = SparseVector(intArrayOf(1,0,1,2,9))
        val v2 = SparseVector(intArrayOf(0,3,0,4,0))
        assertEquals(8,v1.dotProduct(v2))
    }

    @Test
    fun dotProductCase2() {
        val v1 = SparseVector(intArrayOf(0,9,2,0,0))
        val v2 = SparseVector(intArrayOf(0,0,0,1,2))
        assertEquals(0,v1.dotProduct(v2))
    }

    @Test
    fun getNums() {
        val v1 = SparseVector(intArrayOf(0,1,0,0,0))
        assertEquals(intArrayOf(0,1,0,0,0),v1.nums)
    }
}

它编译通过但在运行时失败并出现错误

TestEngine with ID 'junit-jupiter' failed to discover tests

也尝试使用 jdk13.0.2 仍然得到相同的结果

标签: intellij-ideajunit5

解决方案


使用 Gradle Kotlin 作为构建系统并且运行良好


推荐阅读