Gradle 找不到集成测试、JUnit 5 和 Spring Boot:没有找到给定的测试包括:
Posted
技术标签:
【中文标题】Gradle 找不到集成测试、JUnit 5 和 Spring Boot:没有找到给定的测试包括:【英文标题】:Gradle Cannot Find Integration Test, JUnit 5 and Spring Boot: No tests found for given includes: 【发布时间】:2020-11-01 13:53:46 【问题描述】:当我跑步时:
./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
【问题讨论】:
【参考方案1】:我通过将 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 应用程序的一些注释。
【讨论】:
你是从天而降的天使!以上是关于Gradle 找不到集成测试、JUnit 5 和 Spring Boot:没有找到给定的测试包括:的主要内容,如果未能解决你的问题,请参考以下文章
Kotlin 1.5.10,Gradle 7.0.2_2 - 找不到方法 testCompile() group=org.junit.jupiter,name=junit-jupiter-api,ve
Eclipse NoClassDefFoundError 导致 LauncherFactory 找不到使用 JUnit 5 的测试
如何使用 Gradle 和 JUnit 5 仅运行特定测试?