I found the TestExecution class, which exposes a bunch of events that would be incredibly helpful. However, I can't find a reference to it other than MSDN's documentation, and the documentation doesn't provide any hints as far as to how it is used, or how I might get a reference to an instance during a test run.
Looking with .NET Reflector wasn't helpful either - TestExecution
is implemented by one other class, UnitTestExecution
, which is internal. I could not find any other references to either class throughout any of the Microsoft.VisualStudio.QualityTools.* libraries, neither in the form of further implementations nor references as property types in any other classes.
How might I gain access to these events?
An TestExecution
instance is provided to you when implementing a custom TestExtensionExecution
. It provides an Initialize method, which you can override to subscribe to the test events.
This is usually part of an implementation of a custom test attribute in MSTest.
Edit
To create your own test extension, start with creating a new attribute that derives from Microsoft.VisualStudio.TestTools.UnitTesting.TestClassExtensionAttribute
, which is an abstract class requiring you to provide a TestExtensionExecution
via the GetExtension()
method.
Apply your attribute to one of your test methods and you should be able to subscribe to those events during the test (inside your TestExtensionExecution
implementation returned by the attribute)
Note that you also have to implement a ITestMethodInvoker
which you should be able to create from the TetMethodInvokerContext.TestMethodInfo
property supplied to the TestExtensionExecute.CreateTestMethodInvoker
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With