Include tests from other module

为君一笑 提交于 2021-02-08 08:42:14

问题


My project looks like this:

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

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

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/**'   
}

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.


回答1:


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

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

in module1 build.gradle

test.dependsOn(':module2: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.

also, you can put dependsOn inside your task.

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

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.



来源:https://stackoverflow.com/questions/45754005/include-tests-from-other-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!