【问题标题】:Gradle Cannot Find Integration Test, JUnit 5 and Spring Boot: No tests found for given includes:Gradle 找不到集成测试、JUnit 5 和 Spring Boot:没有找到给定的测试包括:
【发布时间】: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
} 

【问题讨论】:

    标签: spring-boot gradle junit build.gradle junit5


    【解决方案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 应用程序的一些注释。

    【讨论】:

    • 你是从天而降的天使!
    猜你喜欢
    • 1970-01-01
    • 2020-07-27
    • 2020-12-30
    • 1970-01-01
    • 2018-08-09
    • 2021-01-24
    • 2018-06-06
    • 2014-04-23
    • 1970-01-01
    相关资源
    最近更新 更多