Skip to content

Testcontainers with MSTest #1170

Answered by HofmeisterAn
jc1231 asked this question in Q&A
Discussion options

You must be logged in to vote

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.:

[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.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by HofmeisterAn
Comment options

You must be logged in to vote
1 reply
@HofmeisterAn
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants