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
Copy file name to clipboardExpand all lines: explain-integration-testing-patterns.md
+19-12Lines changed: 19 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ This guide explains two different approaches for setting up integration tests wi
7
7
When writing integration tests that use Microcks and Kafka containers, you have two main architectural choices:
8
8
9
9
1.**IClassFixture Pattern**: Multiple container instances, isolated per test class
10
-
2.**ICollectionFixture Pattern**: Single shared container instance, optimized for performance
10
+
2.**ICollectionFixture Pattern**: A set of shared container instances (e.g., one Microcks container and one Kafka container) used by all test classes for optimal performance and resource efficiency
11
11
12
12
## Pattern 1: IClassFixture - Isolated Test Classes
13
13
@@ -19,7 +19,7 @@ When writing integration tests that use Microcks and Kafka containers, you have
@@ -34,8 +34,15 @@ public class MyTestClass : IClassFixture<MicrocksWebApplicationFactory<Program>>
34
34
### Implementation Example
35
35
36
36
#### Step 1: WebApplicationFactory with Dynamic Ports
37
+
38
+
> **Note:**
39
+
> The implementation of `OrderServiceWebApplicationFactory` (or `MicrocksWebApplicationFactory`) must be adapted depending on the fixture pattern:
40
+
>
41
+
> - With **IClassFixture**, each test class gets its own factory and containers. You must allocate **dynamic ports** for Kestrel, Kafka, and all services, because static port mapping (like `kafka:9092:9092`) is not possible—otherwise, you will have port conflicts if tests run in parallel. All port assignments must be programmatic and injected into your test server and mocks.
42
+
>
43
+
> - With **ICollectionFixture** (shared collection), a single factory and set of containers are shared for all tests. You allocate ports only once, which simplifies configuration and avoids conflicts. This is why the shared collection pattern is recommended for most test suites.
0 commit comments