首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不是由"gradle构建“运行的单元测试

不是由"gradle构建“运行的单元测试
EN

Stack Overflow用户
提问于 2014-10-17 19:59:04
回答 1查看 4.8K关注 0票数 3

我惊讶地注意到,当我运行时,我的单元测试不再运行:

代码语言:javascript
复制
gradle build

为了运行单元测试,我需要显式地发出一个gradle test

注意,我最近修改了我的build.gradle,并增加了对集成测试的支持。我的build.gradle如下:

代码语言:javascript
复制
buildscript {
    def springBootVersion = "1.2.0.BUILD-SNAPSHOT"

    repositories {
        mavenCentral()
        maven { url "http://repo.spring.io/release" }
        maven { url "http://repo.spring.io/milestone" }
        maven { url "http://repo.spring.io/snapshot" }
    }
    dependencies {      
        classpath ("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'spring-boot'

sourceSets {
    generated {
        java {
            srcDirs = ['build/generated-sources/java']
        }
    }

    integrationTest {
        java.srcDir file('src/it/java')
        resources.srcDir file('src/it/resources')
        compileClasspath = sourceSets.main.output + configurations.testRuntime
        runtimeClasspath = output + compileClasspath
    }
}

configurations {
    querydslapt
}

dependencies {
    def springSecurityVersion = "4.0.0.M2"
    def springBootVersion = "1.2.0.BUILD-SNAPSHOT"
    def springSessionVersion = "1.0.0.BUILD-SNAPSHOT"
    def hibernateVersion = "4.3.6.Final"
    def javaxMailVersion = "1.4.7"
    def queryDslVersion = "3.4.3"
    def thymeleafTilesVersion = "2.1.1.RELEASE"
    def apacheCommonsLang = "3.1"
    def javaxValidationApi = "1.1.0.Final"
    def javaxActivation = "1.1.1"
    def commonsCodec = "1.5"
    def jstl = "1.2"
    def hibernateJpa = "1.0.0.Final"
    def cglibNodep = "2.2.2"
    def commonsIo = "2.4"
    def javaxTransactionJta = "1.1"
    def jacksonHibernate4 = "2.3.2"

    def mockitoVersion = "1.9.5"
    def hamcrestVersion = "1.3"
    def festVersion = "1.4"
    def gatlingVersion = "2.0.1"

    compile project(":bignibou-client")

    compile("log4j:log4j")
    compile("org.springframework.boot:spring-boot-starter")
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter-tomcat")
    compile("org.apache.commons:commons-lang3:${apacheCommonsLang}")
    compile("org.springframework:spring-core")
    compile("org.springframework:spring-beans")
    compile("javax.validation:validation-api:${javaxValidationApi}")
    compile("org.hibernate:hibernate-validator")
    compile("org.springframework:spring-context-support")
    compile("javax.mail:mail:${javaxMailVersion}")
    compile("javax.activation:activation:${javaxActivation}")
    compile("joda-time:joda-time")
    compile("commons-codec:commons-codec:${commonsCodec}")
    compile("org.springframework.security:spring-security-core:${springSecurityVersion}")
    compile("org.springframework.security:spring-security-config:${springSecurityVersion}")
    compile("org.springframework.security:spring-security-web:${springSecurityVersion}")    
    compile("org.thymeleaf:thymeleaf-spring4")    
    compile("org.thymeleaf.extras:thymeleaf-extras-tiles2:${thymeleafTilesVersion}")   
    compile("org.thymeleaf.extras:thymeleaf-extras-tiles2-spring4:${thymeleafTilesVersion}")   
    compile("org.thymeleaf.extras:thymeleaf-extras-springsecurity3")
    compile("javax.servlet:jstl:${jstl}")
    compile("mysql:mysql-connector-java")
    compile("org.hibernate:hibernate-core:${hibernateVersion}")
    compile("org.hibernate:hibernate-entitymanager")
    compile("org.hibernate.javax.persistence:hibernate-jpa-2.1-api:${hibernateJpa}")
    compile("commons-collections:commons-collections")
    compile("cglib:cglib-nodep:${cglibNodep}")
    compile("javax.transaction:jta:${javaxTransactionJta}")
    compile("org.springframework:spring-jdbc")
    compile("org.springframework:spring-orm")
    compile("com.zaxxer:HikariCP")
    compile("commons-pool:commons-pool")
    compile("org.thymeleaf:thymeleaf")
    compile("org.springframework.data:spring-data-commons")
    compile("org.springframework.data:spring-data-jpa")
    compile("com.mysema.querydsl:querydsl-core:${queryDslVersion}")
    compile("com.mysema.querydsl:querydsl-jpa:${queryDslVersion}")
    compile("org.springframework:spring-aspects")
    compile("commons-io:commons-io:${commonsIo}")
    compile("com.fasterxml.jackson.core:jackson-core")
    compile("com.fasterxml.jackson.core:jackson-annotations")
    compile("com.fasterxml.jackson.datatype:jackson-datatype-hibernate4:${jacksonHibernate4}")
    compile("org.springframework:spring-tx")
    compile("javax.cache:cache-api")
    compile("org.springframework.data:spring-data-redis")
    compile("redis.clients:jedis")
    compile("org.springframework.session:spring-session:${springSessionVersion}")
    compile("org.springframework.cloud:spring-cloud-spring-service-connector")
    compile("org.springframework.cloud:spring-cloud-heroku-connector")
    compile("org.springframework.cloud:spring-cloud-localconfig-connector")

    querydslapt "com.mysema.querydsl:querydsl-apt:${queryDslVersion}"

    testCompile("junit:junit")
    testCompile("org.springframework:spring-test")
    testCompile("org.jbehave.web:jbehave-web-selenium:3.5.5")
    testCompile("org.jbehave:jbehave-core:3.8")
    testCompile("org.jbehave:jbehave-spring:3.7.5")
    testCompile("org.mockito:mockito-all:${mockitoVersion}")
    testCompile("org.hamcrest:hamcrest-core:${hamcrestVersion}")
    testCompile("org.hamcrest:hamcrest-integration:${hamcrestVersion}")
    testCompile("org.hamcrest:hamcrest-all:${hamcrestVersion}")
    testCompile("org.easytesting:fest-assert:${festVersion}")
    testCompile("org.hsqldb:hsqldb")
    testCompile("org.hamcrest:hamcrest-library")
    testCompile("io.gatling.highcharts:gatling-charts-highcharts:${gatlingVersion}")
    testCompile("org.springframework.security:spring-security-test:${springSecurityVersion}")
}

task generateQueryDSL(type: JavaCompile, group: 'build', description: 'Generates the QueryDSL query types') {
    source = sourceSets.main.java
    classpath = configurations.compile + configurations.querydslapt
    options.compilerArgs = [
            "-proc:only",
            "-processor", "com.mysema.query.apt.jpa.JPAAnnotationProcessor"
    ]
    destinationDir = sourceSets.generated.java.srcDirs.iterator().next()
}

test {
   reports.html.destination = file("$reports.html.destination/unit")
   reports.junitXml.destination = file("$reports.junitXml.destination/unit")
}

task integrationTest(type: Test) {
    testClassesDir = sourceSets.integrationTest.output.classesDir
    classpath = sourceSets.integrationTest.runtimeClasspath
    reports.html.destination = file("$reports.html.destination/integration")
    reports.junitXml.destination = file("$reports.junitXml.destination/integration")
}

compileJava {
    dependsOn generateQueryDSL
    source generateQueryDSL.destinationDir
}

compileGeneratedJava {
    dependsOn generateQueryDSL
    options.warnings = false
    classpath += sourceSets.main.runtimeClasspath
}

check.dependsOn integrationTest

clean {
    delete sourceSets.generated.java.srcDirs
}

repositories {
    mavenLocal()
    mavenCentral()
    maven { url "http://repo.spring.io/release" }
    maven { url "http://repo.spring.io/milestone" }
    maven { url "http://repo.spring.io/snapshot" }
}

当我发布a:gradle build时,有人能帮我找出什么能阻止我的单元测试被运行吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-18 13:35:25

我发现了所观察到的行为的原因,即单元测试没有由我的gradle构建运行:

问题很简单,考虑到我配置integrationTest任务的方式,特别是我添加的dependsOn (check.dependsOn integrationTest),我的集成测试在单元测试之前运行了,而且由于前者失败了,所以从未达到单元测试。

(我现在需要找到一种方法,让我的单元测试(test)任务在集成测试之前运行,但我想我会为此提出另一个问题。)

编辑:下面是如何实现它(集成测试之前的单元测试):

代码语言:javascript
复制
check.dependsOn integrationTest
integrationTest.dependsOn test
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26432580

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档