Search code examples
javajunitgradlecontinuous-integrationacceptance-testing

In gradle how do you create separate test reports for separate tasks?


I have three test source sets

/src/tests/...
src/test-integration/
src/test-acceptance/

gradle build only runs the unit tests while I have separate tasks for running test-integration and test-acceptance. This setup, basically:

task acceptanceTest(type: Test) {
    description = "Runs acceptance tests"
    testReportDirName ="acceptance"
    testClassesDir = sourceSets.acceptanceTest.output.classesDir
    classpath += sourceSets.test.runtimeClasspath + sourceSets.acceptanceTest.runtimeClasspath
    useJUnit()
    testLogging {
      events "passed", "skipped", "failed"
    }
}

Now my only problem is that I'd like acceptance/integration tests to print their reports somewhere other than "test" folder, since they over-write one another. Basically I'd like to change the testReportDirName property but only for a task.


Solution

  • You can change the default test results and reports directories as such:

    task acceptanceTest(type: Test) {
        reports.html.destination = file("$reports.html.destination/acceptance")
        reports.junitXml.destination = file("$reports.junitXml.destination/acceptance")
    }