NUnit - cleanup after test failure

后端 未结 11 952
盖世英雄少女心
盖世英雄少女心 2020-12-24 05:09

We have some NUnit tests that access the database. When one of them fails it can leave database in inconsistent state - which is not an issue, since we rebuild database for

11条回答
  •  感情败类
    2020-12-24 06:13

    Since version 2.5.7, NUnit allows Teardown to detect if last test failed. A new TestContext class allows tests to access information about themselves including the TestStauts.

    For more details, please refer to http://nunit.org/?p=releaseNotes&r=2.5.7

    [TearDown]
    public void TearDown()
    {
        if (TestContext.CurrentContext.Result.Status == TestStatus.Failed)
        {
            PerformCleanUpFromTest();
        }
    }
    

提交回复
热议问题