Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make NUnit stop executing tests on first failure

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 stop executing as soon as a single failure is detected.

Is there a way to do this?

like image 808
willem Avatar asked Oct 05 '11 07:10

willem


2 Answers

Using nunit-console, you can achieve this by using the /stoponerror command line parameter.

See here for the command line reference.

like image 147
Lukazoid Avatar answered Sep 18 '22 18:09

Lukazoid


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.

like image 41
Vapour in the Alley Avatar answered Sep 20 '22 18:09

Vapour in the Alley