testfx icon indicating copy to clipboard operation
testfx copied to clipboard

Develop Retry Attribute for TestMethod

Open shayan0v0n opened this issue 1 year ago • 3 comments

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
}

shayan0v0n avatar Jun 22 '24 08:06 shayan0v0n

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

Evangelink avatar Jun 22 '24 19:06 Evangelink

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

shayan0v0n avatar Jun 23 '24 03:06 shayan0v0n

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

Evangelink avatar Jun 24 '24 08:06 Evangelink