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
Reuse is an experimental feature designed to simplify and enhance the development experience. Instead of disposing resources after the tests are finished, enabling reuse will retain the resources and reuse them in the next test run. Testcontainers assigns a hash value according to the builder configuration. If it identifies a matching resource, it will reuse this resource instead of creating a new one. Enabling reuse will disable the resource reaper, meaning the resource will not be cleaned up.
4
+
5
+
```csharp title="Enable container reuse"
6
+
_=newContainerBuilder()
7
+
.WithReuse(true);
8
+
```
9
+
10
+
The reuse implementation does not currently consider (support) all builder APIs when calculating the hash value. Therefore, collisions may occur. To prevent collisions, simply use a distinct label to identify the resource.
11
+
12
+
```csharp title="Label container resource to identify it"
13
+
_=newContainerBuilder()
14
+
.WithReuse(true)
15
+
.WithLabel("reuse-id", "WeatherForecast");
16
+
```
17
+
18
+
!!!warning
19
+
20
+
Reuse does not replace singleton implementations to improve test performance. Prefer proper shared instances according to your chosen test framework.
21
+
22
+
Calling `Dispose()` on a reusable container will stop it. Testcontainers will automatically start it in the next test run. This will assign a new random host port. Some services (e.g. Kafka) require the random assigned host port on the initial configuration. This may interfere with the new random assigned host port.
/// <exception cref="ArgumentException">Thrown when a mandatory Docker resource configuration is not set.</exception>
127
133
protectedvirtualvoidValidate()
128
134
{
129
-
conststringmessage="Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured. You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit:\nhttps://dotnet.testcontainers.org/custom_configuration/";
135
+
conststringcontainerRuntimeNotFound="Docker is either not running or misconfigured. Please ensure that Docker is running and that the endpoint is properly configured. You can customize your configuration using either the environment variables or the ~/.testcontainers.properties file. For more information, visit:\nhttps://dotnet.testcontainers.org/custom_configuration/";
0 commit comments