如何使用Spek

我试过这个示例 ,但是会引发一个语法错误。 有没有其他的方式来测试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

你从spek站点剪切和粘贴一个旧的语法:)你需要在第二个括号之前的函数名 ,因为错误提示:use { init { instead of {{

 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一样使用Kotlin的任何测试框架。 使用Kotlin,Maven和JUnit的示例项目可以在这里找到。

看起来像你使用0.1-SNAPSHOT版本。 请尝试当前版本0.1.188