microsoft / testfx

MSTest framework and adapter
MIT License
680 stars 247 forks source link

Develop Retry Attribute for TestMethod #3161

Open shayan0v0n opened 3 weeks ago

shayan0v0n commented 3 weeks ago

Summary

I'm curious to know if there's any built-in mechanism to retry tests. Case in point, I have a unit test code something like this:

[TestMethod]
public async Task Get_Banner_ReturnOK()
{
    //tests
}

Im just looking for something I Can retry this TestMethod Twice or more, something like this:

[TestMethod]
[Retry(2)]
public async Task Get_Banner_ReturnOK()
{
    //tests
}
Evangelink commented 3 weeks ago

When using MSTest runner, you can opt-in for the retry extension (see https://learn.microsoft.com/dotnet/core/testing/unit-testing-platform-extensions-policy#retry) that would allow for a global retry policy feature but at the moment nothing is designed to allow retry at test level.

This is something we are planning to bring (cc @MarcoRossignoli and @nohwnd).

shayan0v0n commented 3 weeks ago

opt-in for the retry extension (see https://learn.microsoft.com/dotnet/core/testing/unit-testing-platform-extensions-policy#retry)

I see, It's looks better

Evangelink commented 2 weeks ago

I'll keep this issue opn as we do plan to have this feature or something similar.