I'd like to log some contextual information when tests fail (like capturing screenshots). Is there any extensibility point in NUnit framework where i can do it? Ideally it would be:
[TearDown]
public void Down(AssertionException ex) {}
but we don't have it. I tried to create an add-in but don't know how to register it in run-time:
[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 UI tests. Install()
method is just not get called. Any tips would be appreciated.
Update: for an add-in to be registered tests have to run with NUnit runner (in my case it was TestDriven.Net plugin for VS) and EventListener
members are get properly called. The problem is that they all called after TearDown/TestFixtureTearDown methods (my context is lost).
Tried to use TestContext.CurrentContext.Result
in my TearDown but accessing either State
or Status
property throws NullReferenceException
:(
After upgrading to NUnit 2.6
TestContext.CurrentContext
started working as expected.