3

I am trying to reduce the time taken to run tests using gradle. Since there are multiple projects, one of the ways that I can think of doing that is to split tests into Unit and Integration tests. For each project, I have created two different tasks: unitTests task and integrationTests task.

Assume for simplification, that we always run gradle build -x test before running tests. In such a scenario, I am trying to get to state where I can run the tasks unitTests and integrationTests in parallel.

Currently I have seen failures where one of the tasks starts compiling the project leading to the other task failing with the error : "Cannot read zip file" which is likely because the JAR that the project depends on is now being updated by the other process. This seems to be likely because we have compileJava and compileTestJava as dependent tasks which interfere with dependent projects leading to a failure.

Wondering if there is a way in gradle to do the following :

  1. Run only tests and not compile anything (to the tune of surefire:test in maven).
  2. If not, is there settings that can be specified in build.gradle to tell gradle not to modify files but just to run tests.
Vaibhav Agarwal
  • 121
  • 1
  • 2
  • 7

1 Answers1

1

Gradle does not (yet) support running multiple tasks of the same project in parallel. However when running tests, these can be run in parallel inside a given test task.

For your issues of having errors potentially due to files being changed while other things run, make sure Gradle knows about all the dependencies between tasks as it will be the best way of solving these problems.

As for work avoidance, Gradle is optimised to only do the minimum required, including tasks up to date checks, compilation avoidance and more. So invoking test will only compile code if there were changes since last execution.

Louis Jacomet
  • 13,661
  • 2
  • 34
  • 43