2

Following on from this question.

If I have a build with two instances of the Test task, what is the best (cleanest, least code, most robust) way to completely separate those two tasks so that their outputs don't overlap?

I've tried setting their testResultsDir and testReportsDir properties, but that didn't seem to work as expected. (That is, the output got written to separate directories, but still the two tasks re-ran their respective tests with each run.)

1
  • can you share your buildscript? normally, seperated testresultdir and testreportdir should do the trick Commented Oct 1, 2012 at 22:08

4 Answers 4

6

Update for the current situation as of gradle 1.8: The testReportDir and reportsDir properties in dty's answer are deprecated since gradle 1.3. Test results are now separated automatically in the "test-results" directory and to set different destination directories for the HTML reports, call

tasks.withType(Test) {
    reports.html.destination = file("${reporting.baseDir}/${name}")
}
Sign up to request clarification or add additional context in comments.

Comments

0

Yet again, Rene has pointed me in the right direction. Thank you, Rene.

It turns out that this approach does work, but I must have been doing something wrong.

For reference, I added the following to my build after all the Test tasks had been defined:

tasks.withType(Test) {
    testReportDir = new File("${reportsDir}/${testReportDirName}/${name}")
    testResultsDir = new File("${buildDir}/${testResultsDirName}/${name}")
}

This will cause all instances of the Test task to be isolated from each other by having their task name as part of their directory hierarchy.

However, I still feel that this is a bit evil and there must be a cleaner way of achieving this that I haven't yet found!

Comments

0

Ingo Kegel's answer doesn't address the results directory, only the reports directory. Which means that a test report for a particular test type could be built that includes more test results than just that type. This can be addressed by setting the results directory as well.

tasks.withType(Test) {
    reports.html.destination = file("${reporting.baseDir}/${name}")
    reports.junitXml.destination = file("${testResultsDir}/${name}")
}

Comments

0

Just an update. The reports.html.destination way is deprecated.

This is the "new" way (Gradle > 4.x):

tasks.withType(Test) {
  reports.html.setDestination file("${reporting.baseDir}/${name}")
}

Comments

Your Answer

Draft saved
Draft discarded

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.