-
Notifications
You must be signed in to change notification settings - Fork 325
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
dotnet test
crashes with System.Exception: Unable to read beyond the end of the stream
if code under tests calls System.Environment.Exit
#3658
Comments
- Due to microsoft/vstest#3658 it is not possible to test code that exits the process on error - Create a base class for nnyeah exceptions that we want to explicitly report (and not crash), ConversionException - Move Main to Main2 and wrap it in a try/catch for this exception - I did not catch everything as for now I want to crash with stack trace on unexpected failures
- Due to microsoft/vstest#3658 it is not possible to test code that exits the process on error - Create a base class for nnyeah exceptions that we want to explicitly report (and not crash), ConversionException - Move Main to Main2 and wrap it in a try/catch for this exception
This is expected, any testhost disconnect, is considered a crash/abort, unless vstest.console told that testhost that it is okay to exit. Your test stops the testhost, and with that, it also stops the test framework, adapter, and other logic responsible for sending back the data. So that is a crash from the point of view of vstest.console. Do you have a better suggestion how to handle this? Would you expect us to ignore the call to .Exit? And do nothing? |
Hmm, is it possible from VSTests's perspective to detect an exit vs a crash? If the line said something like:
when System.Environment.Exit was called instead of a crash, it might have made it more clear that some library multiple levels down was calling System.Environment.Exit (which I admit is a bad idea and I fixed). |
Crash in vstest language is any unexpected stop of the testhost before the vstest.console tells it to stop (by sending the terminate request). This includes exiting with exit 0. |
Related issue #2952 |
Description
Any usage of
System.Environment.Exit
in code under test withdotnet test
crashes the test runner with a mysterious stack:Steps to reproduce
dotnet new nunit
dotnet test
Expected behavior
Some error message that says the process under test exited unsuspectingly. The phrase
Test host process crashed
kinda got that across, but it didn't crash, it exit'ed.Actual behavior
Environment
Microsoft (R) Test Execution Command Line Tool Version 17.2.0 (x64)
dotnet-sdk-6.0.301-rtm.22254.17-osx-x64/dotnet dotnet test
The text was updated successfully, but these errors were encountered: