我的项目如下所示:
├───module1-test-cases
│ └───src
│ └───test
│ └───groovy
│ └───specs
│ └───module1test
└───module2-test-cases
└───src
└───test
└───groovy
└───specs
└───module2test
有很多不同的模块,每个模块都有自己的 build.gradle 文件,所以我可以为单独的模块运行测试
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 test 任务时,它会从当前模块和我想要的模块运行所有测试。
最佳答案
如果这是一个多项目,运行 test
在根目录上将运行所有模块中的所有测试。
如果你想运行 module1
运行时总是测试 module2
测试你可以依赖于测试任务。
在模块 1 build.gradle
test.dependsOn(':module2:test')
这将运行模块 2
test
运行模块1之前的任务test
任务,如果你运行 root test
任务是 不会运行它们两次。 另外,你可以把
dependsOn
在你的任务里面。test{
dependsOn ':othermodule:test'
exclude '**/smth/**'
}
Gradle 将负责运行测试类,您无需说明要运行哪些类。测试发现(取决于您的项目结构和源集)将为您完成。
关于gradle - 包括来自其他模块的测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45754005/