【发布时间】:2016-05-23 13:34:36
【问题描述】:
对 Kotlin 有点熟悉,我想介绍另一个 Android-Java 项目,仅作为测试的第一步。我决定直接从Spek开始。
我在待测模块的build.gradle中添加了如下依赖:
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 repo 的 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 测试的任何其他配置步骤?
【问题讨论】:
标签: android unit-testing android-studio testing kotlin