question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to clone a Container to avoid initialization cost for each test case

See original GitHub issue

We 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:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
dotnetjunkiecommented, Oct 25, 2022

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.

0reactions
erdalsivricommented, Oct 25, 2022

Thanks Steven, it is definitely helpful!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found