
21 May 2024 Leave a comment Tech-Help
When working with large projects that consist of multiple subprojects in Gradle, it can be beneficial to aggregate all test results into a single report. This allows for easier access and review of test outcomes across the entire project. Below, we provide a step-by-step guide to help you achieve this using the TestReport functionality in Gradle.
Project Structure
Consider a project structure as follows:
. |--ProjectA |--src/test/... |--build |--reports |--tests |--index.html (test results) |--ProjectB |--src/test/... |--build |--reports |--tests |--index.html (test results)
Disabling Individual Test Reports
First, disable the individual test reports for each subproject. This will prevent the generation of separate reports for each subproject and allow us to consolidate them into a single report.
subprojects {
apply plugin: 'java'
// Disable the test report for the individual test task
test {
reports.html.enabled = false
}
}
Creating a Consolidated Test Report
Next, create a testReport
task in the root project that will aggregate the test results from all subprojects:
task testReport(type: TestReport) {
destinationDir = file("$buildDir/reports/allTests")
// Include the results from the `test` task in all subprojects
reportOn subprojects*.test
}
This script sets the destination directory for the aggregated report and specifies that the report should include results from the test tasks in all subprojects.
Running the TestReport Task
To ensure that the testReport
task runs after the subproject tests complete, add the following line to the build script:
tasks('test').finalizedBy(testReport)
This ensures that the testReport
task is executed after all subproject tests have finished running.
Updated Approach for Gradle 7.5.1 and Above
For users of Gradle 7.5.1 and above, there are some updates to the TestReport
task. The reportOn
method has been deprecated and replaced with testResults
:
subprojects {
apply plugin: 'java'
}
task testReport(type: TestReport) {
destinationDir = file("$buildDir/reports/allTests")
// Include the results from the `test` task in all subprojects
testResults.from = subprojects*.test
}
Note that the testResults
property is still incubating as of Gradle 7.5.1.
Alternative Option: test-report-aggregation Plugin
Gradle 7.4 introduced the test-report-aggregation
plugin, which can also be used to aggregate test results:
plugins {
id 'test-report-aggregation'
}
With this plugin, you can invoke test reports through the testSuiteAggregateTestReport
task.
Conclusion
Aggregating test results in a multiproject Gradle setup can significantly streamline the process of reviewing test outcomes. By following the steps outlined above, you can create a consolidated test report that provides a comprehensive view of your project’s test results.
Enhancing Test Automation with Repeato
For those looking to further streamline their testing processes, consider using Repeato, a no-code test automation tool for iOS and Android. Repeato helps you create, run, and maintain automated tests for your apps efficiently. Its intuitive test recorder and scripting interface make it easy for both beginners and advanced testers to automate complex use cases. Additionally, Repeato supports testing websites inside an Android emulator or device, with explicit web testing support coming later this summer.
Explore more about Repeato and how it can enhance your testing workflows by visiting our documentation or blog.
Like this article? there’s more where that came from!
- Resolving the “xcrun: error: invalid active developer path” Error on macOS
- Adding Existing Frameworks in Xcode 4: A Comprehensive Guide
- Disabling ARC for a Single File in Xcode: A Step-by-Step Guide
- Resolving the Xcode-Select Active Developer Directory Error
- Resolving the “Multiple Commands Produce” Error in Xcode 10