向 Gradle 添加额外的测试套件 [英] Adding an additional test suite to Gradle

查看:35
本文介绍了向 Gradle 添加额外的测试套件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 Gradle (1.4) 添加到具有多个测试套件的现有项目中.位于 src/test/java 中的标准单元测试成功运行,但我无法设置运行位于 src/integration-test/java.

I am attempting to add Gradle (1.4) to an existing project that has multiple test suites. The standard unit test located in src/test/java ran successfully, but I am having trouble setting up a task to run the JUnit test located in src/integration-test/java.

当我运行 gradle intTest 时,对于 src/main 中的类,我遇到了几个 cannot find symbol 错误.这让我相信依赖关系设置不正确.我如何设置 intTest 以便它运行我的 JUnit 集成测试?

When I run gradle intTest I get several cannot find symbol errors for classes in src/main. This leads me to believe that the dependencies are not set up correctly. How do I setup intTest so that it will run my JUnit integration tests?

build.gradle

apply plugin: 'java'

sourceCompatibility = JavaVersion.VERSION_1_6

sourceSets {
    integration {
        java {
            srcDir 'src/integration-test/java'
        }
        resources {
            srcDir 'src/integration-test/resources'
        }
    }
}

dependencies {
    compile(group: 'org.springframework', name: 'spring', version: '3.0.7')

    testCompile(group: 'junit', name: 'junit', version: '4.+')
    testCompile(group: 'org.hamcrest', name: 'hamcrest-all', version: '1.+')
    testCompile(group: 'org.mockito', name: 'mockito-all', version: '1.+')
    testCompile(group: 'org.springframework', name: 'spring-test', version: '3.0.7.RELEASE')

    integrationCompile(group: 'junit', name: 'junit', version: '4.+')
    integrationCompile(group: 'org.hamcrest', name: 'hamcrest-all', version: '1.+')
    integrationCompile(group: 'org.mockito', name: 'mockito-all', version: '1.+')
    integrationCompile(group: 'org.springframework', name: 'spring-test', version: '3.0.7.RELEASE')
}


task intTest(type: Test) {
    testClassesDir = sourceSets.integration.output.classesDir
    classpath += sourceSets.integration.runtimeClasspath
}

详细信息:Gradle 1.4

Details: Gradle 1.4

解决方案:我没有为集成测试源集设置编译类路径(见下文).在我的 I 代码中,我将编译类路径设置为 sourceSets.test.runtimeClasspath 以便我没有integrationCompile"的重复依赖项

Solution: I had not set the compile classpath for the integration test source set (see below). In my I code I set the compile class path to sourceSets.test.runtimeClasspath so that I don't have the duplicate dependencies for "integrationCompile"

sourceSets {
    integrationTest {
        java {
            srcDir 'src/integration-test/java'
        }
        resources {
            srcDir 'src/integration-test/resources'
        }
        compileClasspath += sourceSets.main.runtimeClasspath
    }
}

推荐答案

集成"源集尚未配置其编译和运行时类路径.这就是为什么它无法从您的主要源集中找到类的原因.您可以通过以下方式配置编译和运行时类路径:

the "integration" sourceSet has not configured its compile and runtime classpath. That's why it can't find the classes from your main sourceset. you can configure the compile and runtime classpath in the following way:

sourceSets {
    integTest {
        java.srcDir file('src/integration-test/java')
        resources.srcDir file('src/integration-test/resources')
        compileClasspath = sourceSets.main.output + configurations.integTest
        runtimeClasspath = output + compileClasspath
    }
}

这篇关于向 Gradle 添加额外的测试套件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆