You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it could be useful to have the current retry attempt count be accessibile from TestContext.
Background and Motivation
One of the test projects I have creates files as part of each test so that test runs can be easily analyzed without rerunning tests in debug mode (this is useful for finding errors in CI). The names of the files involve the test's display name as well as what the test is currently doing.
Proposed Feature
It'd be useful if the TestContext had an attribute that was able to keep track of the retry count.
[TestClass]publicclassMyTestClass{publicTestContextTestContext{get;set;}=null!;protectedstringGetFileName(){vartestName=(TestContext.TestName!=TestContext.TestDisplayName)?$"{TestContext.TestName}.{TestContext.TestDisplayName}":$"{TestContext.TestDisplayName}";// use new TestAttemptCount property so the name is unique and we don't have to manually track it for each test method:return$"{testName}-{TestContext.TestAttemptCount}"}[TestMethod][Retry(3)]publicasyncTaskFlakeyTest(){// send http request to external server/interact with an external service// validate response}[TestCleanup]publicasyncTaskCleanup(){if(TestContext.CurrentTestOutcome==UnitTestOutcome.Failed){stringfileName=GetFileName();// save response to a file (in my case failing Playwright traces are saved to a file)}}}
@Evangelink Per the current design, I think the only way is to add TestContext to RetryContext and leave it up to individual retry attribute implementations to properly update a property on TestContext. But we can't guarantee that attribute authors will respect this properly. What do you think?
Summary
I think it could be useful to have the current retry attempt count be accessibile from TestContext.
Background and Motivation
One of the test projects I have creates files as part of each test so that test runs can be easily analyzed without rerunning tests in debug mode (this is useful for finding errors in CI). The names of the files involve the test's display name as well as what the test is currently doing.
Proposed Feature
It'd be useful if the TestContext had an attribute that was able to keep track of the retry count.
Alternative Designs
Leave it as is, if people need to keep track of the Retry count then they can handle it themselves with a static variable.
As done here:
https://github.com/microsoft/testfx/blob/main/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/RetryTests.cs#L94
The text was updated successfully, but these errors were encountered: