feat: Introduce a new Testcontainers.Xunit package #1165
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This pull request introduces a new
Testcontainers.Xunit
NuGet package.It provides two main classes to simplify working with Testcontainers within xUnit.net tests.
ContainerTest
is a base class for tests needing one container per test method.ContainerFixture
is a fixture that can be injected into test classes that need one container per test class (a.k.a. singleton container instance).Both support logging, respectively through
ITestOutputHelper
andIMessageSink
which are the standard xUnit.net logging mechanisms.DbContainerTest
andDbContainerFixture
are also provided to ease working with database containers. They provide methods to simplify the creation ofDbConnection
instances.Why is it important?
This will greatly reduce boilerplate code needed when using Testcontainers with xUnit.net, both for Testcontainers consumers and for the Testcontainers tests themselves.
Related issues
Follow-ups
I have another branch (feature/Testcontainers.Xunit+samples) where I have started using
Testcontainers.Xunit
in the Testcontainers tests themselves. I have currently updated MongoDbContainerTest, ClickHouseContainerTest, MariaDbContainerTest and PostgreSqlContainerTest. You can have a look at them to see how the tests are simplified by using the new base classes or fixtures.I'm not sure yet whether updating all the Testcontainers tests should be part of this pull request or part of a subsequent pull request.
I've been using xUnit.net extensively so I'm pretty confident about the design of this new package. I'm not familiar enough with either NUnit or MSTest to propose similar packages, maybe someone else can step in.