Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Introduce a new Testcontainers.Xunit package #1165

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

0xced
Copy link
Contributor

@0xced 0xced commented Apr 27, 2024

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 and IMessageSink which are the standard xUnit.net logging mechanisms.

DbContainerTest and DbContainerFixture are also provided to ease working with database containers. They provide methods to simplify the creation of DbConnection 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.

Copy link

netlify bot commented Apr 27, 2024

Deploy Preview for testcontainers-dotnet ready!

Name Link
🔨 Latest commit 93f372d
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-dotnet/deploys/662e19b8dbd3a200087490dc
😎 Deploy Preview https://deploy-preview-1165--testcontainers-dotnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@0xced 0xced force-pushed the feature/Testcontainers.Xunit branch from 680b863 to 93f372d Compare April 28, 2024 09:41
@@ -0,0 +1,41 @@
namespace DotNet.Testcontainers.Xunit;

internal class DbContainerTestMethods(DbProviderFactory dbProviderFactory, string connectionString) : IDbContainerTestMethods, IAsyncDisposable

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interface IDbContainerTestMethods should inherit from IDisposable and IAsyncDisposable instead of the class DbContainerTestMethods. This ensures that clean disposal takes place in every scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement]: Enable built-in support for singleton container instances
2 participants