Testcontainers with MSTest #1170
-
I cannot find any articles or examples or best practices using Testcontainers with MSTest. Everything appears to be for XUnit only.
Are there any examples or guides or is it generally not supported? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The equivalent implementation in MSTest will utilize the [TestClass]
public class MyTestClass
{
private readonly PostgreSqlContainer _postgreSqlContainer = new PostgreSqlBuilder().Build();
[TestInitialize]
public Task TestInitialize()
{
return _postgreSqlContainer.StartAsync();
}
[TestCleanup]
public Task TestCleanup()
{
return _postgreSqlContainer.DisposeAsync().AsTask();
}
} There is nothing special. It works the same way as you would set up any other fixture in MSTest as well. |
Beta Was this translation helpful? Give feedback.
-
@HofmeisterAn Thanks for the info this is helpful. The other issue I'm trying to solve is performance. I've seen many articles on using a single test container per test collection vs one for every individual test. XUnit appears to solve this with something called collection fixtures, I could not find an equivalent for MSTest. Another strange thing I've noticed is even when running a single test, 7+ db containers will get spun up. |
Beta Was this translation helpful? Give feedback.
The equivalent implementation in MSTest will utilize the
[TestInitialize]
and[TestCleanup]
attributes (annotations). Please be aware and implement the async/await pattern properly, e.g.:There is nothing special. It works the same way as you would set up any other fixture in MSTest as well.