java - 如何使用斯派克

标签 java android testing kotlin

我试过了 this sample , 但它会引发语法错误。还有其他方法可以测试 Kotlin 吗?例如,使用 JUnit 还是 Spek?

import kotlin.test.assertEquals
import org.jetbrains.spek.api.Spek

class BlaherSpecs: Spek() {{
    given("Let's test Blaher") {
        var blaher = Blaher()

        on("Blaher blah") {
            val blah = blaher.blah()

            it("should be Blah!") {
                assertEquals("Blah1!", blah)
            }
        }
    }
}}

IDE with errors

最佳答案

您从 spek 站点剪切并粘贴旧语法 :) 您需要在第二个括号之前使用 function name 作为错误提示:使用 { init { 而不是 {{

import kotlin.test.assertEquals
import org.jetbrains.spek.api.Spek

class BlaherSpecs: Spek() { init {
    given("Let's test Blaher") {
        var blaher = Blaher()

        on("Blaher blah") {
            val blah = blaher.blah()

            it("should be Blah!") {
                assertEquals("Blah1!", blah)
            }
        }
    }
}}

关于java - 如何使用斯派克,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34585339/

相关文章:

java - Camel 分离器 : Add individual headers based on body

java - 交错迭代器方法

python - 如何使用 FactoryBoy 指定列表大小

测试遗留代码

java - 从本地文件而不是 URL 解析 XML

java - 我们可以在 TestNG 中将两个注释(IRetryAnalyzer 和优先级)类型作为一个类型传递吗

java - Android 客户端和 Google App Engine API

java - 实例初始化程序中的 StackOverflowError

android - 从安卓删除通知

java - RecyclerView 中的 Android CountDownTimer