question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception in OneTimeSetUp has no stack trace

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
radiycommented, Jan 29, 2021

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.

2reactions
Brondahlcommented, May 28, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unit Tests view - Cannot view stack trace of exception ...
When exception thrown from inside OneTimeSetup, Unit Tests view only shows a useless message: OneTimeSetUp: System.NotImplementedException : The method or ...
Read more >
c# - Nunit test gives result OneTimeSetUp: No suitable ...
I have an issue where NUnit is telling me: "No suitable constructor was found". What causes this? I also get another message: "Exception ......
Read more >
Developers - 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...
Read more >
Stack trace not included in re-thrown exception
When re-throwing an exception, make sure to include the stack trace. Otherwise pertinent debug information is lost. Detector ID.
Read more >
NotImplementedException Class (System)
The NotImplementedException exception indicates that the method or property that you are attempting to invoke has no implementation and therefore provides ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found