首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行Spek测试显示错误“空测试套件”

运行Spek测试显示错误“空测试套件”
EN

Stack Overflow用户
提问于 2016-05-23 13:34:36
回答 1查看 1.3K关注 0票数 2

我对Kotlin有点熟悉,我想向它介绍另一个Android项目,作为测试的第一步。我决定直接从斯派克开始。

我将以下依赖项添加到待测试模块的build.gradle中:

代码语言:javascript
复制
testCompile 'junit:junit:4.12'
testCompile "org.jetbrains.kotlin:kotlin-stdlib:1.0.2"
testCompile "org.jetbrains.kotlin:kotlin-test-junit:1.0.2"
testCompile "org.jetbrains.spek:spek:1.0.25"

除其他外,我还使用了git的规范样例的SimpleTest类:

代码语言:javascript
复制
import org.jetbrains.spek.api.Spek
import kotlin.test.assertEquals


class SampleCalculator
{
    fun sum(x: Int, y: Int) = x + y
    fun subtract(x: Int, y: Int) = x - y
}

class SimpleTest : Spek({
    describe("a calculator") {
        val calculator = SampleCalculator()

        it("should return the result of adding the first number to the second number") {
            val sum = calculator.sum(2, 4)
            assertEquals(6, sum)
        }

        it("should return the result of subtracting the second number from the first number") {
            val subtract = calculator.subtract(4, 2)
            assertEquals(2, subtract)
        }
    }
})

代码编译,在Android中,在类声明旁边显示了一个绿色播放按钮来运行类的测试。然而,这样做会导致

代码语言:javascript
复制
Process finished with exit code 1
Class not found: "com.anfema.ionclient.serialization.SimpleTest"Empty test suite.

我创建了JUnit3和JUnit4测试,它们都运行时没有任何问题。

我是否错过了Spek测试的其他配置步骤?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-23 15:01:02

我的失败是我没有完全/正确地配置Kotlin。

我错过了应用Kotlin插件,它是用以下行完成的:

代码语言:javascript
复制
apply plugin: 'kotlin-android'

buildscript {
    ext.kotlin_version = '1.0.2'
    repositories {
        jcenter()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }

如果要在普通JUnit测试中使用Kotlin代码,这也是必需的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37392478

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档