In theory, this should be possible with your own test extension (derived from TestClassExtensionAttribute), which you would use instead of the standard attribute [TestClass].
This is a bit complicated, as it requires the deployment / registration of your test extension (see "Visual Studio Unit Test Type Extension, Part 1" ).
This will give you access to the event TestExecution.OnTestStopping. In the event handler, you can request cancellation in a specific instance CancellationTokenSource.
How to make CancellationTokenSource.Tokenthe test method available to you. For example, you can use System.AppDomain.CurrentDomain.GetData. In this case, you will also need to process TestExecution.BeforeTestInitializeand use System.AppDomain.CurrentDomain.SetDatato store the information necessary to find the right one CancellationTokenSource. You will probably need to create the TestContext-to- dictionary CancellationTokenSourceto make sure you cancel the correct test.
source
share