Skip to content

AssertException in TearDown hides Exception in Test #4537

Description

@Sputnik24

I know from other comments in issues that it is not recommended to do Assertions during TearDown. Nevertheless, I want to report the following to check if it is a known issue/by design or a bug.

Simple code example to demonstrate the issue:

using NUnit.Framework;

namespace DemoTests; 

public class TearDownTests {
    [Test]
    public void Assertion() {
        Assert.IsTrue(false);
    }

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

    [Test]
    public void Pass() {
        
    }

    [TearDown]
    public void TearDown() {
        Assert.Warn("Warning");
    }
}

Result:

  • Assertion() tests shows both failures and warnings
  • Pass() shows Warning from TearDown
  • Exception() only shows Warning and hides/forgets/overrides the Exception

This happens with any AssertException in TearDown. Of course, when I catch the exception and "rethrough" it using something like Assert.Fail(ex.Message), I see both failures as in Assertion() tests, but for me it is one of the big advantages of NUnit that I don't need to catch all my exceptions to let a test fail but that it fails automatically.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions