Skip to content

armgit / core

Public Imported from GitHub
0

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

Update writing tests in AGENTS.md (#3342)

Koen1908dc6d0d5a
diff --git a/AGENTS.md b/AGENTS.md
index 7d803f141..a7764e789 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -15,8 +15,21 @@ In sandboxed environments, add `--offline` (requires dependencies to already be
### Writing tests
+All backend tests are Groovy Spock specifications. Unit tests live in the project that holds the code, under `<project>/src/test/groovy`. Use an integration test in the `test` project only when the behaviour needs a running manager. Tests for anything under `ui/` follow `ui/AGENTS.md`.
+
Since Spock 2.0, unrolling is the default, don't add un-necessary @Unroll annotations.
+A `WebApplicationException` thrown by a JAX-RS proxy carries a response that holds its connection open until it is closed. Read the status through `ex.response.withCloseable`, so a spec that asserts on many rejections does not run the connection pool dry. The closure result becomes the condition, so assert inside it and return `true`:
+
+```groovy
+then: "the request should be forbidden"
+WebApplicationException ex = thrown()
+ex.response.withCloseable { r ->
+ assert r.status == 403
+ return true
+}
+```
+
### Running tests
When running integration tests, part of the stack (PostgreSQL and Keycloak) must be running. Start it with `docker compose -f profile/dev-testing.yml -p openremote up -d --no-build`.