New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception in OneTimeSetUp has no stack trace #671
Comments
Please clarify "I get..." That is... How are you running the tests and where do you see this message? |
I run them in one of two ways:
Changing to |
If an exception is thrown in OneTimeSetUp, then the tests are not run. Consequently no exception is ever thrown for the individual test case. Instead, it's thrown for the suite or fixture. 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. If you run tests using nunit3-console, we actually report errors at the fixture level as well, so you can see the stack trace there. The same is true if you run using the TestCentric GUI. IOW, at least in my view, this is a limitation of using Test Explorer, which only treats test methods as tests, not test suites. |
Normally, yes. In my case, I was modifying an application to run on both Windows and Linux, and on Linux I got exceptions from GDI-related code ("Parameter is invalid" - not easy to figure that out :) ). I did not have a full IDE available there, only the Occasionally, I have intermittent test failures on the build server, and in those cases the suppressed stack trace makes it very hard to know what's going on.
Forgive me if I misunderstand, but if I interpret you correctly it's NUnit that suppresses the stack trace, and since I observe that an exception has occurred both in Test Explorer/ReSharper and in a test report, it seems to me that the problem lies with NUnit. Or rather, that the only place where a fix is possible is within NUnit. |
Btw, I agree that including the stack trace for each test is a lot of repetetion. However, if I use |
Let me try again... In your sample code, NUnit considers The implementation of The implementation code for Unfortunately, you can't see that! The NUnit3 VS Adapter has the job of translating NUnit's view of the tests to Test Explorer's. In Test Explorer's view, only There doesn't seem to me to be anything more that NUnit itself needs to do. The information is there and is made visible by other runners, like nunit3-console and testcentric-gui. In your case, the actual runner is the dotnet CLI, making use of the adapter. The adapter could do something, but that would probably have to vary depending on the execution environment. When running under the IDE, it could dump more info to the Output window - although that might get very cluttered. When running under vstest or a dotnet command it might write to stdout. In any case, it would have to bypass the normal reporting mechanism to get the information out about a failure that takes place in no recognized "test". |
Ok, I understand now. Thank you for the detailed explanation! I'll report the problem against the other involved components (Test explorer/Resharper/dotnet tooling). |
Or the NUnit3 VS adapter, to which we could transfer this issue if you prefer. |
Aha, I see now that I missed the part about a possible fix/workaround in the adapter. Yes, moving the issue there would be good. Would you like me to do it? |
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. |
Thanks :-) But, closed ? |
User closed... I meant to reopen. |
FYI, you can sort-of bypass this issue, by wrapping all of your
Kinda sucks, but it's better than what you get at the moment. |
I am also hitting this issue with the Test Explorer (or more specifically with ReSharper). I write a number of behavioral tests where the arrange and act happen in the one time setup and the logical assertions are the individual tests. If an exception is thrown during the arrange or the act it is a pain to debug. Work around suggestion accepted. |
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. |
@radiy I only posted a description of how TestExplorer works and how the adapter tries to compensate for it. It's not possible to "reconsider" that - it's just a fact. Are you using TestExplorer in your CI? That seems unlikely. You may want to post info about what you are using, what doesn't work for you and what you would like changed. To be clear, I haven't worked on the adapter for years myself, so I'm only making suggestions. @bronumski I have no idea how they do that, but apparently they have figured out a way. As commercial companies, they're probably not going to tell us. 😞 It's possible they get the info directly from NUnit and not through the adapter. Still, that's good information. It shows that any of these runners - test explorer included - could access and display the info you want to see. That was kind of my point. Although I don't work on the adapter any longer, I do remember how frustrating it was that it tends to be blamed for limitations in the code that calls it. IMO, if you simply accept the fact that Test Explorer does not know about fixture-level failures and will never report them directly, you are a step ahead. Then you can start to imagine workarounds, where the adapter displays the info you need "on the side" i.e. in a fake test or in the output window or as some visible text output elsewhere in the interface. |
Looks like I was a little rushed. Do you think it`s possible to log exception only once, on the first test method. |
Sounds possible! I believe the adapter knows when it's running under vstest vs test explorer. @OsirisTerje will have to give the final answer, since he does the work. 😄 |
@radiy @CharliePoole We do get the stack trace so it should be possible to get this out somehow. If we focus on dotnet test and vstest commandline scenarios it might be even easier. |
@OsirisTerje I recently worked in the adapter quite a bit for a personal project. Is this an issue you'd like a contribution for? I imagine if the TestRunner bubbles these errors up to the adapter we can just write the stacktrace in addition to the message, instead of just the message? |
@svengeance Absolutely! Feel free to add a PR :-) |
@OsirisTerje To be sure - what's the intended solution here? Log the stacktrace on the first test method, log it to the Test Output window, log the full stacktrace on all tests, etc? For giggles I'm investigating manipulating the text on the Fixture itself, but I don't have high hopes for that.. |
Nice, any progress on this? I'm sure the people over at this issue would appreciate this. |
@jamers99 @provegard @svengeance |
Fix for issue #671, exception stacktrace from OneTimeSetup
When an exception is thrown in code called from a
OneTimeSetUp
method, I get:Code to demonstrate the problem:
Versions:
The text was updated successfully, but these errors were encountered: