【发布时间】:2020-07-08 10:24:55
【问题描述】:
我已经在 IntelliJ 中启动了新的 java 11、spring boot 2.3.1 项目。 我想将 spock 添加到依赖项,但是在尝试运行示例测试用例时遇到了问题。
org.junit.runners.model.InvalidTestClassError: Invalid test class 'com.example.SpockSpec':
1. No runnable methods
这是我的依赖项列表:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation "org.codehaus.groovy:groovy-all:$groovyVersion"
testImplementation 'org.spockframework:spock-core:2.0-M2-groovy-3.0'
}
(groovy 版本为 3.0.0)
这是规格:
class SpockSpec extends Specification {
def "result should be true"(){
given:
boolean a = false;
boolean b = true;
when:
boolean result = a || b;
then:
result == true;
}
}
解决方法是在方法之前添加 JUnit 的 @Test 注释,但我不希望这样做。 另外 - 当我这样做时,测试仅在我运行整个班级时才有效。
我该如何解决这个错误?
【问题讨论】:
标签: java spring-boot spock