testcontainers / testcontainers-dotnet

A library to support tests with throwaway instances of Docker containers for all compatible .NET Standard versions.
https://dotnet.testcontainers.org
MIT License
3.65k stars 250 forks source link

[Enhancement]: Purge PostgreSQL data before each test in .NET xUnit #1104

Closed QBT-VinayAdiga closed 4 months ago

QBT-VinayAdiga commented 5 months ago

Problem

I need each test to run independently and with clean database. But the testcontainer-postgresql holds the data across tests.

Solution

Probably an attribute to clean up data before running test.

Benefit

Can test with clean data across tests.

Alternatives

Not that I know of

Would you like to help contributing this enhancement?

Yes

HofmeisterAn commented 5 months ago

Hm, can you elaborate on that? I do not think this is the responsibility of Testcontainers, rather than the responsibility of your test framework and test design. The test frameworks offer several mechanisms to either share fixtures among tests or not. If you need a fresh instance for each test, simply recreate one. Here is the explanation of xUnit.net's Shared Context; similar concepts exist in other test frameworks.

HofmeisterAn commented 4 months ago

As mentioned, I do not believe this is the responsibility of Testcontainers. I will go ahead and close this issue. However, if you could provide additional information about your use case and explain why you believe this enhancement is necessary for Testcontainers, please do not hesitate to reopen it and share your thoughts. IMO, configuring and setting this up through the test frameworks is straightforward.