Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Execute all tests when running gradle test (#2094)

Ekhorn4ea5eaef64fc
diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml
index 8eed4239c..88997ea6f 100644
--- a/.github/workflows/ci_cd.yml
+++ b/.github/workflows/ci_cd.yml
@@ -425,7 +425,7 @@ jobs:
- name: Define backend test command
id: test-backend-command
if: ${{ steps.skip-backend-tests.outputs.value != 'true' }}
- run: echo "value=./gradlew -p test test" >> $GITHUB_OUTPUT
+ run: echo "value=./gradlew test -x npmTest" >> $GITHUB_OUTPUT
- name: Define UI component test command
id: test-ui-components-command
diff --git a/build.gradle b/build.gradle
index 68209b856..45de61eb6 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,6 +3,9 @@ import java.nio.file.Paths
import static org.apache.tools.ant.taskdefs.condition.Os.FAMILY_WINDOWS
import static org.apache.tools.ant.taskdefs.condition.Os.isFamily
+import org.gradle.api.tasks.testing.logging.TestExceptionFormat
+import org.gradle.api.tasks.testing.logging.TestLogEvent
+
// Configure version based on Git tags
apply plugin: 'pl.allegro.tech.build.axion-release'
scmVersion {
@@ -93,7 +96,59 @@ buildscript {
}
subprojects {
+ // Apply only if the project has a 'test' task
+ tasks.withType(Test).configureEach { testTask ->
+ outputs.upToDateWhen { false }
+ useJUnitPlatform()
+
+ testLogging {
+
+ // set options for log level LIFECYCLE
+ events = [
+ TestLogEvent.FAILED,
+ TestLogEvent.PASSED,
+ TestLogEvent.SKIPPED
+ ]
+ exceptionFormat = TestExceptionFormat.FULL
+ showExceptions = true
+ showCauses = true
+ showStackTraces = true
+
+ // set options for log level DEBUG and INFO
+ debug {
+ events = [
+ TestLogEvent.STARTED,
+ TestLogEvent.FAILED,
+ TestLogEvent.PASSED,
+ TestLogEvent.SKIPPED,
+ TestLogEvent.STANDARD_OUT,
+ TestLogEvent.STANDARD_ERROR
+ ]
+ exceptionFormat = TestExceptionFormat.FULL
+ }
+ info.events = debug.events
+ info.exceptionFormat = debug.exceptionFormat
+
+ afterTest { desc, result ->
+ logger.lifecycle "${desc.className} > ${desc.name} took: ${(result.endTime - result.startTime)}ms"
+ }
+
+ afterSuite { desc, result ->
+ if (!desc.parent) { // will match the outermost suite
+ def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} passed, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped)"
+ def startItem = '| ', endItem = ' |'
+ def repeatLength = startItem.length() + output.length() + endItem.length()
+ println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
+ }
+ }
+ }
+ }
+
afterEvaluate { proj ->
+ tasks.withType(Test).configureEach { testTask ->
+ workingDir = findProject(":openremote") != null ? project("").projectDir : rootProject.projectDir
+ }
+
if (proj.plugins.hasPlugin('java')) {
def entityAnnotation = 'Ljakarta/persistence/Entity;'
@@ -136,3 +191,17 @@ subprojects {
}
}
}
+
+// Finalize the gradle test task with the npmTest task so that all tests can be run with gradle test.
+// Runs backend tests first and then frontend tests. UI tests are registered under npmTest to avoid
+// complications when configuring the test task on projects w/o the Java plugin where the test task is
+// already defined. It also allows for easy exclusion using the `-x` argument (e.g. `gradle test -x npmTest`.)
+tasks.register('test') {
+ dependsOn subprojects.collect { it.tasks.matching { it.name == 'test' } }
+}
+tasks.register('npmTest') {
+ dependsOn subprojects.collect { it.tasks.matching { it.name == 'npmTest' } }
+}
+tasks.named('test') {
+ finalizedBy tasks.named('npmTest')
+}
diff --git a/model/build.gradle b/model/build.gradle
index 05c0ce152..01db4ae4e 100644
--- a/model/build.gradle
+++ b/model/build.gradle
@@ -50,10 +50,12 @@ dependencies {
}
}
-test {
- useJUnitPlatform()
+tasks.withType(Test) {
+ environment("OR_LOGGING_CONFIG_FILE", "logging-dev.properties")
}
+test {}
+
base {
archivesName = "openremote-${project.name}"
}
diff --git a/profile/dev-ui.yml b/profile/dev-ui.yml
index 8e9994765..a45754f1e 100644
--- a/profile/dev-ui.yml
+++ b/profile/dev-ui.yml
@@ -34,6 +34,7 @@ services:
service: postgresql
volumes:
- manager-data:/storage
+ - ../tmp/datapoint:/storage/datapoint
# Access directly if needed on localhost
ports:
- "5432:5432"
diff --git a/test/build.gradle b/test/build.gradle
index e3de76700..ea1c1f918 100644
--- a/test/build.gradle
+++ b/test/build.gradle
@@ -1,6 +1,3 @@
-import org.gradle.api.tasks.testing.logging.TestExceptionFormat
-import org.gradle.api.tasks.testing.logging.TestLogEvent
-
plugins {
id 'com.adarshr.test-logger' version '3.1.0'
}
@@ -45,53 +42,7 @@ tasks.withType(Test) {
environment("OR_LOGGING_CONFIG_FILE", "logging-dev.properties")
}
-test {
- outputs.upToDateWhen { false }
- workingDir = findProject(":openremote") != null ? project("").projectDir : rootProject.projectDir
- useJUnitPlatform()
-
- testLogging {
-
- // set options for log level LIFECYCLE
- events = [
- TestLogEvent.FAILED,
- TestLogEvent.PASSED,
- TestLogEvent.SKIPPED
- ]
- exceptionFormat = TestExceptionFormat.FULL
- showExceptions = true
- showCauses = true
- showStackTraces = true
-
- // set options for log level DEBUG and INFO
- debug {
- events = [
- TestLogEvent.STARTED,
- TestLogEvent.FAILED,
- TestLogEvent.PASSED,
- TestLogEvent.SKIPPED,
- TestLogEvent.STANDARD_OUT,
- TestLogEvent.STANDARD_ERROR
- ]
- exceptionFormat = TestExceptionFormat.FULL
- }
- info.events = debug.events
- info.exceptionFormat = debug.exceptionFormat
-
- afterTest { desc, result ->
- logger.lifecycle "${desc.className} > ${desc.name} took: ${(result.endTime - result.startTime)}ms"
- }
-
- afterSuite { desc, result ->
- if (!desc.parent) { // will match the outermost suite
- def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} passed, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped)"
- def startItem = '| ', endItem = ' |'
- def repeatLength = startItem.length() + output.length() + endItem.length()
- println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
- }
- }
- }
-}
+test {}
javadoc {
failOnError = false
diff --git a/ui/build.gradle b/ui/build.gradle
index 58dc5863f..09908cfc3 100644
--- a/ui/build.gradle
+++ b/ui/build.gradle
@@ -18,3 +18,19 @@ afterEvaluate {
task modelWatch {
dependsOn resolveTask(":ui:component:model:build"), resolveTask(":ui:component:rest:build")
}
+
+// Finalize gradle test tasks with npmTest tasks so that gradle :ui:test can also be used to run
+// UI tests. The tests are registered under npmTest to avoid complications when configuring the
+// test task on projects w/o the Java plugin where the test task is already defined.
+subprojects { subproj ->
+ subproj.tasks.matching { it.name == 'npmTest' }.all {
+ subproj.tasks.matching { it.name == 'test' }.all {
+ finalizedBy 'npmTest'
+ }
+ if (!subproj.tasks.findByName('test')) {
+ subproj.tasks.register('test') {
+ finalizedBy 'npmTest'
+ }
+ }
+ }
+}
diff --git a/ui/component/or-translate/build.gradle b/ui/component/or-translate/build.gradle
index 434de64da..b078f2413 100644
--- a/ui/component/or-translate/build.gradle
+++ b/ui/component/or-translate/build.gradle
@@ -18,3 +18,19 @@ tasks.register('prepareUi') {
tasks.register('publishUi') {
dependsOn clean, npmPublish
}
+
+tasks.register('npmBuild', Exec) {
+ mustRunAfter npmClean
+ dependsOn getYarnInstallTask()
+ commandLine npmCommand("yarn"), "run", "build"
+}
+
+tasks.register('npmTest', Exec) {
+ dependsOn getYarnInstallTask()
+ commandLine npmCommand("yarn"), "run", "test"
+}
+
+tasks.register('npmTestUI', Exec) {
+ dependsOn getYarnInstallTask()
+ commandLine npmCommand("yarn"), "run", "test", "--ui"
+}
diff --git a/ui/component/or-translate/package.json b/ui/component/or-translate/package.json
index 5cafe2489..35dd38336 100644
--- a/ui/component/or-translate/package.json
+++ b/ui/component/or-translate/package.json
@@ -12,6 +12,7 @@
"types": "lib/index.d.ts",
"scripts": {
"analyze": "npx cem analyze --config ../custom-elements-manifest.config.mjs",
+ "build": "npx tsc -b",
"test": "npx tsc -b && npx playwright test",
"prepack": "npx rspack"
},