Gotten familiar a bit with Kotlin I wanted to introduce it another Android-Java project, as a first step for testing only. I decided to start straight with Spek.
I added the following dependencies to build.gradle of the module to be tested:
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"
Among others I used the SimpleTest class of spek-samples of the git repo:
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)
}
}
})
The code compiles and in Android Studio I am shown a green play button next to the class declaration to run the tests of the class. However, doing so results in
Process finished with exit code 1
Class not found: "com.anfema.ionclient.serialization.SimpleTest"Empty test suite.
I created JUnit3 and JUnit4 tests of which all ran without any problems.
Did I miss any additional configuration step for Spek tests?
Aucun commentaire:
Enregistrer un commentaire