Integration tests with Gradle Kotlin DSL

前端 未结 4 1002
梦谈多话
梦谈多话 2020-12-31 06:07

I\'m using this blog post to configure integration tests for a Spring Boot project, but I\'m pretty stuck on declaring the source sets. I also found this post on StackOverfl

4条回答
  •  醉话见心
    2020-12-31 06:44

    As of Gradle 5.2.1 see https://docs.gradle.org/current/userguide/java_testing.html#sec:configuring_java_integration_tests

    sourceSets {
        create("intTest") {
            compileClasspath += sourceSets.main.get().output
            runtimeClasspath += sourceSets.main.get().output
        }
    }
    
    val intTestImplementation by configurations.getting {
        extendsFrom(configurations.testImplementation.get())
    }
    
    configurations["intTestRuntimeOnly"].extendsFrom(configurations.runtimeOnly.get())
    
    dependencies {
        intTestImplementation("junit:junit:4.12")
    }
    
    val integrationTest = task("integrationTest") {
        description = "Runs integration tests."
        group = "verification"
    
        testClassesDirs = sourceSets["intTest"].output.classesDirs
        classpath = sourceSets["intTest"].runtimeClasspath
        shouldRunAfter("test")
    }
    
    tasks.check { dependsOn(integrationTest) }
    

提交回复
热议问题