You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The API is a Spring Web REST controller :fileLink[RatingsController]{path="workshop/src/main/java/com/example/demo/api/RatingsController.java"} and exposes two endpoints:
29
+
The API is a Spring Web REST controller :fileLink[RatingsController]{path="src/main/java/com/example/demo/api/RatingsController.java"} and exposes two endpoints:
30
30
31
31
*`POST /ratings { "talkId": ?, "value": 1-5 }` to add a rating for a talk
32
32
*`GET /ratings?talkId=?` to get the histogram of ratings of the given talk
Let's apply it to the `AbstractIntegrationTest` class:
18
+
1. Update the :fileLink[`AbstractIntegrationTest`]{path="src/test/java/com/example/demo/AbstractIntegrationTest.java"} class to add the `@SpringBootTest` annotation:
* `jdbc:tc:` -this part says that we should use Testcontainers as a JDBC provider
36
+
* `postgresql:16-alpine://` - we use a PostgreSQL database, and we select the correct PostgreSQL image from the Docker Hub as the image
37
+
* `testcontainers/workshop` - the host name \(can be anything\) is `testcontainers` and the database name is `workshop`.Your choice!
38
+
39
+
2.Run the tests with the following command:
40
+
41
+
```bash
42
+
./mvnw clean test
43
+
```
44
+
45
+
When the tests run, you'll see log output indicating it is pulling the `postgresql:16-alpine` container image. It will then use this container to run the tests.
46
+
47
+
Eventually, you will see output similar to the following indicating the tests ran successfully:
*`jdbc:tc:` - this part says that we should use Testcontainers as JDBC provider
35
-
*`postgresql:16-alpine://` - we use a PostgreSQL database, and we select the correct PostgreSQL image from the Docker Hub as the image
36
-
*`testcontainers/workshop` - the host name \(can be anything\) is `testcontainers` and the database name is `workshop`. Your choice!
37
62
38
-
## Running tests
63
+
## Running tests with Testcontainers Cloud
39
64
40
-
In order to run these test we'll need a Docker Engine available. To relax the system, we'll use Testcontainers Cloud to spin up Testcontainers-based containers.
65
+
When the tests ran in the previous step, they used the Docker Engine on your machine. However, there are times in which you might not be able to easily run containers (such as in CI pipelines).
41
66
42
-
To enbale it you need to:
67
+
In these environments, Testcontainers Cloud can be used to spin up Testcontainers-based containers. To enable it you need to:
43
68
44
-
1. Go to the [app.testcontainers.cloud](https://app.testcontainers.cloud/) and generate the TC_CLOUD_TOKEN.
69
+
1. Go to the [app.testcontainers.cloud](https://app.testcontainers.cloud/) and generate the `TC_CLOUD_TOKEN`.
45
70
46
-
2. Set the TC_CLOUD_TOKEN as environment variable:
71
+
2. Set the `TC_CLOUD_TOKEN` as environment variable:
47
72
48
73
::variableDefinition[tcc_token]{prompt="What is your TC_CLOUD_TOKEN value?"}
49
74
@@ -65,26 +90,26 @@ To enbale it you need to:
65
90
66
91
Test is green? Good!
67
92
68
-
5. Check the logs.
93
+
5. Check the logs to see the output indicating Testcontainers Cloud is being used:
69
94
70
95
```text
71
-
2025-10-27T21:36:55.945Z INFO 77211 --- [ main] o.t.d.DockerClientProviderStrategy : Found Docker environment with Testcontainers Host with tc.host=tcp://127.0.0.1:43387
72
-
2025-10-27T21:36:55.946Z INFO 77211 --- [ main] org.testcontainers.DockerClientFactory : Docker host IP address is 127.0.0.1
73
-
2025-10-27T21:36:56.055Z INFO 77211 --- [ main] org.testcontainers.DockerClientFactory : Connected to docker:
96
+
2026-03-20T21:36:55.945Z INFO 77211 --- [ main] o.t.d.DockerClientProviderStrategy : Found Docker environment with Testcontainers Host with tc.host=tcp://127.0.0.1:43387
97
+
2026-03-20T21:36:55.946Z INFO 77211 --- [ main] org.testcontainers.DockerClientFactory : Docker host IP address is 127.0.0.1
98
+
2026-03-20T21:36:56.055Z INFO 77211 --- [ main] org.testcontainers.DockerClientFactory : Connected to docker:
74
99
Server Version: 28.3.3 (via Testcontainers Cloud Agent 1.22.0)
75
100
API Version: 1.51
76
101
Operating System: Ubuntu 22.04.5 LTS
77
102
Total Memory: 31556 MB
78
-
2025-10-27T21:36:56.206Z INFO 77211 --- [ main] tc.testcontainers/ryuk:0.8.1 : Creating container for image: testcontainers/ryuk:0.8.1
79
-
2025-10-27T21:36:56.396Z INFO 77211 --- [ main] tc.testcontainers/ryuk:0.8.1 : Container testcontainers/ryuk:0.8.1 is starting: 779608b4dc49f2c37420ea0a39cc90951912fb767d7d7141c1b0ae1db1717989
80
-
2025-10-27T21:36:57.321Z INFO 77211 --- [ main] tc.testcontainers/ryuk:0.8.1 : Container testcontainers/ryuk:0.8.1 started in PT1.114889292S
81
-
2025-10-27T21:36:57.521Z INFO 77211 --- [ main] o.t.utility.RyukResourceReaper : Ryuk started - will monitor and terminate Testcontainers containers on JVM exit
82
-
2025-10-27T21:36:57.523Z INFO 77211 --- [ main] org.testcontainers.DockerClientFactory : Checking the system...
83
-
2025-10-27T21:36:57.530Z INFO 77211 --- [ main] org.testcontainers.DockerClientFactory : ✔︎ Docker server version should be at least 1.6.0
84
-
2025-10-27T21:36:57.532Z INFO 77211 --- [ main] tc.postgres:17-alpine : Creating container for image: postgres:17-alpine
85
-
2025-10-27T21:36:57.679Z INFO 77211 --- [ main] tc.postgres:17-alpine : Container postgres:17-alpine is starting: ed1a75d921ab911896763cde925724777aa6cea00700aec567d6b9a293b1e297
86
-
2025-10-27T21:36:58.939Z INFO 77211 --- [ main] tc.postgres:17-alpine : Container postgres:17-alpine started in PT1.406803125S
87
-
2025-10-27T21:36:58.943Z INFO 77211 --- [ main] tc.postgres:17-alpine : Container is started (JDBC URL: jdbc:postgresql://127.0.0.1:32771/workshop?loggerLevel=OFF)
103
+
2026-03-20T21:36:56.206Z INFO 77211 --- [ main] tc.testcontainers/ryuk:0.8.1 : Creating container for image: testcontainers/ryuk:0.8.1
104
+
2026-03-20T21:36:56.396Z INFO 77211 --- [ main] tc.testcontainers/ryuk:0.8.1 : Container testcontainers/ryuk:0.8.1 is starting: 779608b4dc49f2c37420ea0a39cc90951912fb767d7d7141c1b0ae1db1717989
105
+
2026-03-20T21:36:57.321Z INFO 77211 --- [ main] tc.testcontainers/ryuk:0.8.1 : Container testcontainers/ryuk:0.8.1 started in PT1.114889292S
106
+
2026-03-20T21:36:57.521Z INFO 77211 --- [ main] o.t.utility.RyukResourceReaper : Ryuk started - will monitor and terminate Testcontainers containers on JVM exit
107
+
2026-03-20T21:36:57.523Z INFO 77211 --- [ main] org.testcontainers.DockerClientFactory : Checking the system...
108
+
2026-03-20T21:36:57.530Z INFO 77211 --- [ main] org.testcontainers.DockerClientFactory : ✔︎ Docker server version should be at least 1.6.0
109
+
2026-03-20T21:36:57.532Z INFO 77211 --- [ main] tc.postgres:17-alpine : Creating container for image: postgres:17-alpine
110
+
2026-03-20T21:36:57.679Z INFO 77211 --- [ main] tc.postgres:17-alpine : Container postgres:17-alpine is starting: ed1a75d921ab911896763cde925724777aa6cea00700aec567d6b9a293b1e297
111
+
2026-03-20T21:36:58.939Z INFO 77211 --- [ main] tc.postgres:17-alpine : Container postgres:17-alpine started in PT1.406803125S
112
+
2026-03-20T21:36:58.943Z INFO 77211 --- [ main] tc.postgres:17-alpine : Container is started (JDBC URL: jdbc:postgresql://127.0.0.1:32771/workshop?loggerLevel=OFF)
88
113
```
89
114
90
115
As you can see, Testcontainers quickly discovered your environment and connected to Docker.
@@ -96,7 +121,7 @@ It also performed some pre-flight checks to ensure the environment is valid.
96
121
Changing the PostgreSQL version is as simple as replacing `16-alpine` with, for example, `17-alpine`.
97
122
Try it, but don't forget that it will download the new image from the internet, if it's not already present on your computer.
Copy file name to clipboardExpand all lines: labspace/05-dude-r-u-200-ok.md
+6-5Lines changed: 6 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,16 +3,17 @@
3
3
One of the great features of Spring Boot is the Actuator and its health endpoint.
4
4
It gives you an overview how healthy your app is.
5
5
6
-
The context starts, but what's about the health of the app?
6
+
The context starts, but what about the health of the app? This endpoint can also be used in a test to quickly validate the application starts up completely.
7
7
8
8
## Configure Rest Assured
9
9
10
10
To check the health endpoint of our app, we will use the [RestAssured](http://rest-assured.io/) library.
11
11
12
12
However, before using it, we first need to configure it.
13
-
Update your abstract test class with `setUpAbstractIntegrationTest` method since we will share it between all tests:
0 commit comments