c# - Nunit action attribute: Don't run AfterTest method if any exception -
how prevent running aftertest method if there exception in testmethod?
public class testattribute : attribute, itestaction { public void beforetest(testdetails testdetails) { // run before test // .... } public void aftertest(testdetails testdetails) { // don't run if there exception // how check whether exception thrown nunit // ... } public actiontargets targets { get; private set; } } [test][testattribute] public void testmthod() { throw new exception("test exception"); }
is there way know if exception thrown or assert failed in aftertest method?
note: i'm not interested in details of exception.
if exception thrown in testmthod result error not failure, hence believe in current code block can take advantage of test context this:
public void aftertest(testdetails testdetails) { if(testcontext.currentcontext.result.state == teststate.error) { return; } // don't run if there exception // how check whether exception thrown nunit // ... }
if interested in finding out actual result string is, think need use addins , implement eventlistener.
hope helps
Comments
Post a Comment