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 `@Rule` annotation tells JUnit to notify this field about various events in the test lifecycle.
47
-
In this case, our rule object is a Testcontainers `GenericContainer`, configured to use a specific Redis image from Docker Hub, and configured to expose a port.
57
+
Wrap the containers with `new TestContainersRule(...)` so the containers start and stop, according to the test lifecycle.
58
+
In this case, our rule object is not `static`, so the container will start and stop with every test.
59
+
The test configures `GenericContainer` to use a specific Redis image from Docker Hub, and to expose a port.
48
60
49
61
If we run our test as-is, then regardless of the actual test outcome, we'll see logs showing us that Testcontainers:
50
62
@@ -66,9 +78,9 @@ We can do this in our test `setUp` method, to set up our component under test:
66
78
<!--/codeinclude-->
67
79
68
80
!!! tip
69
-
Notice that we also ask Testcontainers for the container's actual address with `redis.getHost();`,
81
+
Notice that we also ask Testcontainers for the container's actual address with `redis.getHost();`,
70
82
rather than hard-coding `localhost`. `localhost` may work in some environments but not others - for example it may
71
-
not work on your current or future CI environment. As such, **avoid hard-coding** the address, and use
83
+
not work on your current or future CI environment. As such, **avoid hard-coding** the address, and use
72
84
`getHost()` instead.
73
85
74
86
## 4. Run the tests!
@@ -80,4 +92,3 @@ Let's look at our complete test class to see how little we had to add to get up
0 commit comments