包括其他模块的测试 [英] Include tests from other module

查看:53
本文介绍了包括其他模块的测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目如下:

├───module1-test-cases
│   └───src
│       └───test
│           └───groovy
│               └───specs
│                   └───module1test
└───module2-test-cases
    └───src
        └───test
            └───groovy
                └───specs
                    └───module2test

有很多不同的模块,每个模块都有自己的build.gradle文件,因此我可以为单独的模块运行测试

There is a lot different modules, each module has its own build.gradle file, so i can run tests for separate modules

build.gradle的示例

Example of build.gradle

dependencies{
    compile("org.codehaus.groovy:groovy-all:2.3.3")
    compile project(":core")
    compile("commons-codec:commons-codec:1.10")
    testCompile("junit:junit:4.11")
    testCompile project(":module2-test-cases")
}
test{
    exclude '**/smth/**'   
}

我想要包括来自其他模块的测试,因此当我运行gradle测试任务时,它将运行当前模块和我想要的模块中的所有测试.

I want include tests from other module so when i run gradle test task it runs all tests from current module and from module i want.

推荐答案

如果这是一个多项目,则在根目录上运行 test 将在所有模块中运行所有测试.

If this is a multi-project, running test on the root will run all tests in all of the modules.

如果要在运行 module2 测试时始终运行 module1 测试,则可以依赖于测试任务.

If you want to run module1 tests always when runing module2 tests you can depend on the test task.

在module1中 build.gradle

test.dependsOn(':module2:test')

这将在运行module1 test 任务之前先运行module2 test 任务,如果您运行根 test 根任务,则不是将运行两次.

this is going to run module2 test task before running module1 test task and if you run the root test task is not going to run them twice.

此外,您可以在任务中放入 dependsOn .

also, you can put dependsOn inside your task.

test{
    dependsOn ':othermodule:test'
    exclude '**/smth/**'   
}

Gradle将负责运行测试类,您无需说出要运行哪些类.测试发现(取决于您的项目结构和sou​​rceSets)将为您完成

Gradle will take care for running the test classes, you dont need to say which classes you want to run. The test discovery (depending on your project structure and sourceSets) will do it for you.

这篇关于包括其他模块的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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