运行Spek测试显示错误“空测试套件”
与Kotlin熟悉了一下,我想介绍一下另一个Android-Java项目,作为测试的第一步。 我决定直接与Spek开始。
我添加了以下依赖关系来构建要测试的模块的渐变:
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"
其中我使用了SimpleTest类的git仓库的spek-samples:
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 Studio中显示类声明旁边的绿色播放按钮,以运行该类的测试。 但是,这样做会导致
Process finished with exit code 1 Class not found: "com.anfema.ionclient.serialization.SimpleTest"Empty test suite.
我创建了JUnit3和JUnit4测试,其中没有任何问题。
我是否错过了Spek测试的其他配置步骤?
我的失败是我没有完全/正确地配置Kotlin。
我错过了应用Kotlin插件,这是用这些行完成的:
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代码,这也是一个要求。