java - 如果没有 JUnit 的 @Test 注解,Spock 测试用例将无法工作
问题描述
我已经在 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 注释,但我不希望这样做。另外-当我这样做时,测试仅在我运行整个班级时才有效。
如何解决错误?
解决方案
Spock 1 基于 JUnit 4,但 Spock 2 运行在 JUnit 5 平台上,实现了自己的引擎(不是 JUnit Jupiter)。所以也许你想先阅读一些文档,然后升级到 JUnit 5(不是老式的)。在“入门”一章的手册顶部有一个子章节“Spock 示例项目”。
推荐阅读
- firebase - 如何在flutter中验证firebase auth中的电子邮件?
- python - 缩小 AWS 部署包的大小
- python - 使用实时数据创建的线条放大 tkinter 画布
- java - 需要更改通过 JMX 公开的指标的名称
- angular - 在开发配置上打开源映射代码的问题
- google-apps-script - Bigquery 的自定义连接器 - Data Studio 用于缓存数据
- c++ - 如何从给定键的 interval_maps 中获取值?
- android - 为 android 构建 ionic/react - 无效的项目类型“react”
- sql - Calculate count after recursive CTE in ms sql
- asp.net - IDataProtectionProvider 的目的字符串数组如何将默认值作为项目的物理路径?