nunit3-vs-adapter: Exception in OneTimeSetUp has no stack trace

When an exception is thrown in code called from a OneTimeSetUp method, I get:

Exception doesn’t have a stacktrace

Code to demonstrate the problem:

public class Tests
{
    [OneTimeSetUp]
    public void Setup()
    {
        throw new Exception("oops");
    }

    [Test]
    public void Test1()
    {
        Assert.Pass();
    }
}

Versions:

  • .NET Core 3.0
  • NUnit 3.12.0
  • NUnit3TestAdapter 3.15.1
  • Microsoft.NET.Test.SDK 16.3.0

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 5
  • Comments: 25 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Because TestExplorer (and I believe Resharper as well) never reports errors on the fixture, we report the message as if the exception was thrown for the test case itself - otherwise, you would never see it. We do not report the stack trace simply because that would be a lot of repetition and you can generally find where the exception was thrown pretty easily, if not by inspection, then in the debugger.

Please reconsider, this is HUGE waste of time. Think about CI scenario, sometimes setup is pretty complex and when it went wrong all you get is NullReferenceException.

FYI, you can sort-of bypass this issue, by wrapping all of your OneTimeSetUp methods in:

try
{
  //... do setup
}
catch(Exception e)
{
  throw new Exception(e.ToString(), e);
}

Kinda sucks, but it’s better than what you get at the moment.

Nice, any progress on this? I’m sure the people over at this issue would appreciate this.

Transferred!

@OsirisTerje I realize you may have other issues that relate to this one, but I transferred it in case it has added useful info.