1
Kotlinにはおなじみになっています。テストの第一歩として、別のAndroid-Javaプロジェクトを導入したかったのです。私はSpekとまっすぐに始めることに決めました。Spekテストを実行すると "Empty test suite"というエラーが表示される
Iは、試験されるモジュールの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"
を私はgitのレポのSPEK-サンプルのSimpleTestクラスを使用する:
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テストの設定手順が追加されませんでしたか?