我尝试过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)
}
}
}
}}

发布于 2016-01-04 22:23:54
您剪切并粘贴了spek站点中的旧语法:)您需要在第二个括号之前使用函数名,因为错误提示:使用{ 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)
}
}
}
}}发布于 2016-01-04 16:53:44
您可以通过与Java完全相同的方式在Kotlin中使用任何测试框架。可以在here中找到使用Kotlin、Maven和JUnit的示例项目。
发布于 2016-01-04 17:03:35
看起来您使用的是0.1-SNAPSHOT版本。请尝试当前版本的0.1.188
https://stackoverflow.com/questions/34585339
复制相似问题