我写了以下测试:
@RunWith(SpringJUnit4ClassRunner::class)
class KotlinTest : BehaviorSpec() {
init {
given("a stack") {
val stack = Stack<String>()
`when`("an item is pushed") {
stack.push("kotlin")
then("the stack should not be empty") {
stack.isEmpty() shouldBe true
}
}
`when`("the stack is popped") {
stack.pop()
then("it should be empty") {
stack.isEmpty() shouldBe false
}
}
}
}
}
当我尝试运行它时,出现以下错误:
java.lang.Exception: No runnable methods
at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:191)
at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:128)
at org.junit.runners.ParentRunner.validate(ParentRunner.java:416)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:84)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:138)
我知道问题是我正在尝试使用带有 Spring 的 KotlinTest 编写测试,但我该怎么做呢?我应该使用什么跑步者?
示例测试不需要spring,这只是我为了隔离问题而写的一个简单示例