TestExamplesDotnet icon indicating copy to clipboard operation
TestExamplesDotnet copied to clipboard

Reuse database container

Open Rick-van-Dam opened this issue 1 year ago • 1 comments

Currently the startup time of the database container dominates the total run time when running a few or a single test. Reusing the container instance would largely solve this.

At the moment of writing this Testcontainers .NET does not support this yet but works seems to be underway to change this: https://github.com/testcontainers/testcontainers-dotnet/pull/1051

When this is supported switch over to reusing the container instance.

Rick-van-Dam avatar Dec 01 '23 08:12 Rick-van-Dam

Some preparations were done namely generating stable names per run of the tests. A hash of the script that is used to create the database is used in the name of the database. This allows future runs to reuse that same database without having to recreate it from scratch saving time. With this the first test you run can finish in under a second instead of several seconds.

However I ran into some issues with the testcontainer container reuse feature itself. When running multiple test assemblies at the same time for instance multiple containers were created. When you try to run tests again testcontainers would crash and the only way to fix this is to manually stop the containers. For this reason I didnt enabled container reuse by default yet.

Rick-van-Dam avatar Apr 10 '24 18:04 Rick-van-Dam