5

Does anyone know how to stop xUnit.Net from throwing a Xunit.SDK.TraceAssertException when the code-under-test triggers a failing System.Diagnostics.Debug.Assert?

I often use guards in DEBUG mode to alert other developers that they are using the API incorrectly. However, with xUnit.Net throwing this exception, it's breaking my unit tests.

2 Answers2

3

As referenced by this answer, you should be able to add the following to your `App.config' unit testing file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.diagnostics>
        <assert assertuienabled="false"/>
    </system.diagnostics>
</configuration>
dochoffiday
  • 5,515
  • 6
  • 32
  • 41
0

I would normally only use debug assert for internal/private code where there can be no possible side effects from mutated state. That kind of code would not be exposed in my public API and therefore I wouldn't unit test it.

I don't think you can avoid the issues you are having with xunit assertions if you are manufacturing states where debug assert exceptions would be triggered in your tests, so if the intention is to test public api's I wouldn't use Debug.Assert but instead use parameter validation type exceptions, and if the intention is to test private internal code, there is plenty of literature out there to suggest this is not a good idea.

Scott Mackay
  • 1,194
  • 10
  • 34
  • 4
    Not sure I wholly subscribe to the logic that "one must never test private code". –  Oct 12 '15 at 12:44