How to clone a Container to avoid initialization cost for each test case
See original GitHub issueWe create/initialize a separate Container for each test case to be able to completely isolate tests. We’ve tried using a single shared container but Singleton registrations cause leaks between tests (we were able to use a shared Container for some of the tests and these tests did execute faster).
What we need is a very fast Container “clone” operation so that we can keep using Container per test but still have fast tests. This is probably not feasible but I still wanted to create this bug because maybe you’ll have another suggestion for us. Maybe there is a better way to isolate tests and still use a single container. Note that we do run each test case in a separate AsyncScope but as I mentioned above, Singleton objects cause issues.
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top Results From Across the Web
How to reuse Testcontainers between multiple ...
Accepted answer is great but the problem is you still have to repeat the configurations(creating, starting and etc.) for each integration tests.
Read more >Init Containers
Init containers support all the fields and features of app containers, including resource limits, volumes, and security settings.
Read more >Using Docker to Manage Your Test Database(s) | Blog
Docker is a great tool for packaging and distributing test databases among your team and testing environment.
Read more >Best practices for building containers
This article describes a set of best practices for building containers. These practices cover a wide range of goals, from shortening the ...
Read more >Run multiple services in a container
You can connect multiple containers using user-defined networks and shared volumes. The container's main process is responsible for managing all processes that ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I added an Integration Testing Guide to the Simple Injector documentation. It talks about unit vs integration testing and performance considerations when using a DI Container, and shows a way to reuse the same container instance for the entire test suite. I considered adding information about using a container pool, but that solution is likely only more complex compared to using a single container, while being slower, and providing no additional benefits.
Let me know whether that information is helpful.
Thanks Steven, it is definitely helpful!