lundi 25 juillet 2016

Nunit action attribute: Don't run AfterTest method if any exception

How to prevent running AfterTest method if there is any exception in testmethod?

public class TestAttribute : Attribute, ITestAction
    {
        public void BeforeTest(TestDetails testDetails)
        {
            // Run before test
            // ....
        }

        public void AfterTest(TestDetails testDetails)
        {
            // don't run it if there is any exception
            // how to check whether an exception is thrown from Nunit

            // ...
        }

        public ActionTargets Targets { get; private set; }
    }

[Test][TestAttribute]
public void TestMthod()
{
   throw new Exception("test exception");
}

Is there a way to know if an exception is thrown in AfterTest method?

Aucun commentaire:

Enregistrer un commentaire