I want to record some contextual information on failed tests (for example, capturing screenshots). Is there any extension point in the NUnit framework where I can do this? Ideally, this would be:
[TearDown] public void Down(AssertionException ex) {}
but we donβt have it. I tried to create an add-in, but I donβt know how to register it at runtime:
[NUnitAddin] public class UITestCase : TestCaseBase, NUnit.Core.EventListener, NUnit.Core.Extensibility.IAddin { ............. public void UnhandledException(Exception exception){} public bool Install(NUnit.Core.Extensibility.IExtensionHost host) { IExtensionPoint listeners = host.GetExtensionPoint("EventListeners"); listeners.Install(this); return true; }
}
UITestCase
is my base class for all user interface tests. Install()
method is simply not called. Any advice would be appreciated.
Update: for the add-in to be registered, must run with the NUnit runner (in my case it was TestDriven.Net for VS) and the EventListener
members will get the proper call. The problem is that they are all called after the TearDown / TestFixtureTearDown methods (my context is lost).
Tried to use TestContext.CurrentContext.Result
in my TearDown, but getting access to the State
or Status
NullReferenceException
: (
source share