Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle multi project - sharing test code between modules

ProjectA contains an abstract unit test, TestA.

ProjectB has a test called TestB, which needs to extends from TestA, to fulfil the test requirements for this specific implementation.

I've added to the build.gradle configuration file on ProjectB, ProjectA as a dependency compilation test:

testCompile project(':ProjectA')

Also, as a dependency compilation:

compile project(':ProjectA')

Although I'm able to extend from TestA, when I try to run TestB I get the next error:

error: cannot find symbol class TestA

So, is there any way to share test code between modules?

Thanks.

like image 594
Víctor Albertos Avatar asked Jun 17 '16 23:06

Víctor Albertos


People also ask

Does gradle run tests in parallel?

Parallel executionBy using the --parallel switch, you can force Gradle to execute tasks in parallel as long as those tasks are in different projects. You could see big improvements in build times as soon as you enable parallel builds.

What is subproject in gradle?

The subproject producer defines a task named buildInfo that generates a properties file containing build information e.g. the project version. You can then map the task provider to its output file and Gradle will automatically establish a task dependency. Example 2.

How do I run all unit tests in gradle?

Run Gradle testsIn your Gradle project, in the editor, create or select a test to run. From the context menu, select Run <test name>. icon in the left gutter. If you selected the Choose per test option, IntelliJ IDEA displays both Gradle and JUnit test runners for each test in the editor.


1 Answers

As mentioned in this question you should add dependency on test sources like this:

compileTestJava.dependsOn tasks.getByPath(':projectA:testClasses')
testCompile files(project(':projectA').sourceSets.test.output.classesDir)
like image 51
tkachuko Avatar answered Oct 29 '22 09:10

tkachuko