-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Debug.Fail or Debug.Assert causing entire test run to be aborted #12031
Comments
@dotnet/dotnet-diag |
In coreclr we call We (the runtime team) don't really have any control over how the VSTest behaves, you may be able to start a discussion at the VSTest repo. I suspect they are not able to substantially change the behavior since |
@davmason So what is the official guidance around unit testing a codebase which makes extensive use of |
For .NET Core 3.0, |
Sample tests you can look at to see the usage: Examples: As opposed to when you don't use Trace.Listeners Debug.Fail would not get skipped as shown here Note, internally to set up the test we used WriteAssert (https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.Debug/tests/DebugTests.cs#L62-L88) to mock the actual FailCore and WriteCore behavior via reflection So as @stephentoub mentioned above, using cc: @jkotas |
This is fixed in .NET Core 3.0. Previews are available here: https://blogs.msdn.microsoft.com/dotnet/2019/01/29/announcing-net-core-3-preview-2/ . Please give it a try and let us know if you find any issues. |
Confirmed - in .NET Core 3.0, |
@maryamariyan Thanks for the sample code. For 2.2 I'll just set the value of Debug.s_ShowDialog via reflection and we're in great shape! |
In our code base, we have a lot of calls to
Debug.Assert()
andDebug.Fail()
. We also have a lot of unit tests which go through those code paths and make sure things don't break down.When running those unit tests in .NET Framework, we could remove the
DefaultTraceListener
fromDebug.Listeners
, and the tests would run along happily.However, in .NET Core (2.2), there doesn't seem to be any opportunity to access
Debug.Listeners
. When we run our unit tests, the first one that hits aDebug.Fail()
or a failedDebug.Assert()
will cause the rest of the entire test run to be aborted.Steps to replicate:
Debug.Fail()
.Debug.Fail()
, the second method does nothing.Actual Result: The first test fails to complete, and the second test doesn't execute at all. In the "Tests" category of the VS Output window, you get "The active test run was aborted. Reason: Assertion Failed" with a stack trace.
Expected Result: The first test fails to complete, but the rest of the tests keep getting run.
Note: I entered this under
coreclr
because I think the real issue is that we no longer have the ability to modify the debug listeners, like we could in .NET Framework.The text was updated successfully, but these errors were encountered: