spring-boot - Gradle 找不到集成测试、JUnit 5 和 Spring Boot:没有找到给定的测试包括:
问题描述
当我运行时:
./gradlew :integrationTest --tests com.shohidulhaque.whatdoyouthinkauthorizationservice.WhatdoyouthinkauthorizationserviceApplicationTests2
我得到以下输出:
No tests found for given includes: [com.shohidulhaque.whatdoyouthinkauthorizationservice.WhatdoyouthinkauthorizationserviceApplicationTests2](--tests filter)
我相信我已经正确设置了 build.gradle。
我已将此项目上传到 github。它可以在https://github.com/shohidulhaque/integrationTestRepo找到
如果有人能提供帮助,我将不胜感激。我在用:
Gradle 6.4.1 openjdk 版本“11.0.7” 2020-04-14
这是我的 build.gradle 文件:
plugins {
id 'org.springframework.boot' version '2.3.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'org.asciidoctor.convert' version '1.5.8'
id 'java'
id 'groovy'
id 'java-library'
}
group = 'com.shohidulhaque'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
ext {
set('snippetsDir', file("build/generated-snippets"))
}
sourceSets {
integrationTest {
groovy.srcDir "$projectDir/src/integrationTest/groovy"
resources.srcDir "$projectDir/src/integrationTest/resources"
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
}
}
configurations {
integrationTestImplementation.extendsFrom testImplementation
integrationTestRuntime.extendsFrom testRuntimeOnly
}
task integrationTest(type: Test) {
description = 'Runs integration tests.'
group = 'verification'
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
}
check.dependsOn integrationTest
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-ldap'
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.data:spring-data-rest-hal-browser'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test')
{
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'com.unboundid:unboundid-ldapsdk'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
testImplementation group: 'org.codehaus.groovy', name: 'groovy', version: '3.0.4'
testImplementation group: 'org.spockframework', name: 'spock-core', version: '2.0-M3-groovy-3.0'
testImplementation (group: 'org.spockframework', name: 'spock-spring', version: '2.0-M3-groovy-3.0')
}
test {
outputs.dir snippetsDir
useJUnitPlatform()
}
asciidoctor {
inputs.dir snippetsDir
dependsOn test
}
解决方案
我通过将 integrationTest 修改为:
task integrationTest(type: Test) {
useJUnitPlatform()
description = 'Runs integration tests.'
group = 'verification'
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
}
这将启用 JUnit 5。我认为默认情况下它会启用 Junit 4,并且这无法识别用于测试 Spring Boot 应用程序的一些注释。
推荐阅读
- animation - Flutter 中的布局过渡动画
- c++ - 如何在 C++ 中将命令行参数的整个集合(char**)作为只读传递?
- reactjs - 是形成一个展示组件还是一个容器组件
- scala - 在 ScalaPB 编译器中避免内部类
- javascript - 如何允许数组中的不同图像链接到不同的 url 网页
- php - Websocket 服务器不允许来自客户端的新连接,卡在 socket_read(没有错误)
- c# - 目标框架符号未定义
- java - NiFi - JOLT Spec 添加自定义字段
- oauth-2.0 - 具有 oauth2 和 spring 安全性的 AWS api 网关
- sql - 如何使表 b 的列仅对表 a 中的不同外键条目唯一