How to make NUnit stop executing tests on first failure

前端 未结 3 1401
自闭症患者
自闭症患者 2020-12-17 14:32

We use NUnit to execute integration tests. These tests are very time consuming. Often the only way to detect a failure is on a timeout.

I would like the tests to sto

3条回答
  •  情深已故
    2020-12-17 15:04

    I'm using NUnit 3 and the following code works for me.

    public class SomeTests {
        private bool stop;
    
        [SetUp]
        public void SetUp()
        {
            if (stop)
            {
                Assert.Inconclusive("Previous test failed");
            }
        }
    
        [TearDown]
        public void TearDown()
        {
            if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
            {
                stop = true;
            }
        }
    }
    

    Alternatively you could make this an abstract class and derive from it.

提交回复
热议问题