100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Aggregate test reports (#2691)
Koen1ad9cfbe08fd
diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.ymlindex f2c5cddf8..f55a9280d 100644--- a/.github/workflows/ci_cd.yml+++ b/.github/workflows/ci_cd.yml@@ -740,18 +740,37 @@ jobs:timeout-minutes: 20#continue-on-error: true- - name: Archive backend test results+ - name: Generate backend test reports+ id: backend-test-reports+ run: |+ if [ "$IS_MAIN" = "true" ]; then+ ./gradlew unitTestReport combinedCoverageReport+ echo "coverage=build/reports/jacoco/combinedCoverageReport/html" >> $GITHUB_OUTPUT+ else+ echo "coverage=test/build/reports/jacoco/test/html" >> $GITHUB_OUTPUT+ fi+ env:+ IS_MAIN: ${{ steps.is_main_repo.outputs.value }}++ - name: Archive integration test resultsif: always()uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4with:- name: backend-test-results- path: test/build/reports/tests+ name: integration-test-results+ path: test/build/reports/tests/test++ - name: Archive unit test results+ if: ${{ steps.is_main_repo.outputs.value == 'true' }}+ uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4+ with:+ name: unit-test-results+ path: build/reports/tests/test/aggregated-results- name: Archive coverage reportuses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4with:name: coverage-report- path: test/build/reports/jacoco/test/html+ path: ${{ steps.backend-test-reports.outputs.coverage }}- name: Cleanup backend testsif: ${{ steps.test-backend-command.outputs.value != '' }}diff --git a/build.gradle b/build.gradleindex 87e40702f..f3e6cca5a 100644--- a/build.gradle+++ b/build.gradle@@ -6,6 +6,22 @@ import static org.apache.tools.ant.taskdefs.condition.Os.isFamilyimport org.gradle.api.tasks.testing.logging.TestExceptionFormatimport org.gradle.api.tasks.testing.logging.TestLogEvent+apply plugin: 'java-base'+apply plugin: 'test-report-aggregation'+apply plugin: 'jacoco'++jacoco {+ toolVersion = "0.8.14"+}++subprojects {+ if (project.path.startsWith(':ui')) return+ pluginManager.withPlugin('java') {+ apply plugin: 'jacoco'+ jacoco { toolVersion = "0.8.14" }+ }+}+tasks.register('npmTest') {group = 'verification'description = 'Runs all UI tests sequentially (component then app)'@@ -58,6 +74,95 @@ gradle.projectsEvaluated {}}+dependencies {+ subprojects.forEach { subproject ->+ if (subproject.path.startsWith(':ui')) return+ subproject.pluginManager.withPlugin('java') {+ // Aggregate unit test results spread over different projects+ if (subproject.path != ':test') {+ testReportAggregation project(subproject.path)+ }+ }+ }+}++reporting {+ reports { // Task which generates an aggregated unit test report+ unitTestReport(AggregateTestReport) {+ testSuiteName = 'test'+ }+ }+}++tasks.named('unitTestReport').configure {+ doLast {+ def htmlIndex = new File(destinationDirectory.get().asFile, "index.html")+ println "Aggregated Unit Test Results: file://${htmlIndex.absolutePath}"+ }+}++def getBackendProjects = {+ subprojects.findAll { !it.path.startsWith(':ui') && it.pluginManager.hasPlugin('java') }+}++def getActiveTestTasks = {+ getBackendProjects().collectMany { it.tasks.withType(Test) }.findAll { it.name == 'test' }+}++tasks.register('checkCoverageDataExists') {+ group = 'reporting'+ mustRunAfter(getBackendProjects().collect { "${it.path}:test" })+ doLast {+ def testTasks = getActiveTestTasks()+ def hasFiles = testTasks.any {+ it.extensions.findByType(JacocoTaskExtension)?.destinationFile?.exists()+ }+ // Check if any of the configured execution data files exist on disk+ if (!hasFiles) {+ println "Please run the following task to be able to generate a report."+ println "Required tasks: ${testTasks.collect { it.path }.join(', ')}"+ println "Run: gradle test -x npmTest checkCoverageDataExists"+ throw new StopExecutionException()+ }+ }+}++// We replace the 'jacoco-report-aggregation' plugin with the following task to+// ensure we get a combined coverage report for the unit- and integration tests+tasks.register('combinedCoverageReport', JacocoReport) {+ group = 'reporting'+ description = 'Generates a unified coverage report for all Unit and Integration tests'+ dependsOn('checkCoverageDataExists')+ mustRunAfter(getBackendProjects().collect { "${it.path}:test" })++ reports {+ xml.required = true+ html.required = true+ }++ executionData.setFrom(project.provider {+ getActiveTestTasks().collect {+ it.extensions.findByType(JacocoTaskExtension)?.destinationFile+ }.findAll { it != null && it.exists() }+ })++ sourceDirectories.setFrom(project.provider {+ getBackendProjects().collectMany { it.sourceSets.main.allJava.srcDirs }+ })++ classDirectories.setFrom(project.provider {+ def dirs = getBackendProjects().collectMany { it.sourceSets.main.output.classesDirs.files }+ files(dirs).asFileTree.matching {+ include 'org/openremote/**'+ }+ })++ doLast {+ def htmlIndex = new File(reports.html.outputLocation.get().asFile, "index.html")+ println "Combined Code Coverage: file://${htmlIndex.absolutePath}"+ }+}+// Configure version based on Git tagsapply plugin: 'pl.allegro.tech.build.axion-release'scmVersion {@@ -130,10 +235,8 @@ tasks.register('checkFilesGitIgnoredNew', Exec) {def gitFile = Paths.get(projectDir.path, '.git').toFile()checkFilesGitIgnoredNew.enabled = gitFile.exists() && gitFile.isDirectory()-tasks.register('clean') {- doLast {- delete 'tmp'- }+tasks.named('clean') {+ delete 'tmp'}diff --git a/project.gradle b/project.gradleindex ff9f52c9b..0bc8f860b 100644--- a/project.gradle+++ b/project.gradle@@ -2,19 +2,6 @@import org.jetbrains.gradle.ext.JUnit-apply plugin: 'jacoco'--jacoco {- toolVersion = "0.8.14"-}--tasks.withType(JacocoReport) {- reports {- xml.required = true- html.required = true- }-}-import java.nio.file.Filesimport java.nio.file.Pathsimport java.nio.file.attribute.PosixFileAttributesdiff --git a/test/build.gradle b/test/build.gradleindex 3f43cb0ac..4532d142b 100644--- a/test/build.gradle+++ b/test/build.gradle@@ -1,5 +1,4 @@plugins {- id "jacoco"id 'com.adarshr.test-logger' version '4.0.0'}@@ -46,36 +45,7 @@ tasks.withType(Test) {environment("OR_LOGGING_CONFIG_FILE", "logging-dev.properties")}-test {- finalizedBy jacocoTestReport-}--jacocoTestReport {- dependsOn test-- sourceDirectories.from(- project(':agent').sourceSets.main.allSource.srcDirs,- project(':container').sourceSets.main.allSource.srcDirs,- project(':manager').sourceSets.main.allSource.srcDirs,- project(':model').sourceSets.main.allSource.srcDirs,- project(':model-util').sourceSets.main.allSource.srcDirs,- project(':setup').sourceSets.main.allSource.srcDirs- )-- classDirectories.from(- project(':agent').sourceSets.main.output,- project(':container').sourceSets.main.output,- project(':manager').sourceSets.main.output,- project(':model').sourceSets.main.output,- project(':model-util').sourceSets.main.output,- project(':setup').sourceSets.main.output- )-- reports {- xml.required = true- html.required = true- }-}+test {}javadoc {failOnError = false