1

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.

sann05
  • 414
  • 7
  • 18

2 Answers2

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.

LazerBanana
  • 6,865
  • 3
  • 28
  • 47
  • If at least a single test falls in **:module2:test** target **test** task from **module1** doesn't start at all. Can i somehow just run them both? – sann05 Aug 30 '17 at 12:28
  • @sann05 then you want to run the tests not matter if they fail or not? That is default behaviour to interrupt the build when a test fails. – LazerBanana Aug 30 '17 at 12:35
0

For Gradle version 7.4.2 add in the build.gradle of the module that depends on test classes from other module:

testImplementation project(':otherModule').sourceSets.test.output
Olivier Meurice
  • 554
  • 8
  • 17