Disable System.Diagnostics.Debug.Assert dialogs
While executing my integration tests today, I was greeted with the excellent Assertion.Failed dialog which is displayed when using System.Diagnostics. This dialog caused a problem on the build server as it was waiting for someone to click Ignore - that someone never came!
If you haven't saw the Debug.Assert code before, it basically looks like this:
[Test]
public void DebugAssert()
{
System.Diagnostics.Debug.Assert(false);
}
When the Assert fails, the dialog is displayed.
The solution, add an App.Config file to your test suite. Within the XML will clear the trace listeners, now when assert is called nothing happens because nothing is listening for it and the code continues. While executing unit tests this is fine - we just don't want the dialog being displayed.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<trace>
<listeners>
<clear/>
</listeners>
</trace>
<assert assertuienabled="false" />
</system.diagnostics>
</configuration>
If you was interested in the debug.assert messages, you could have hooked up a different listener to write out the message to the console or a file. This is what TestDriven.NET does, if an assertion is hit it writes the message to the output window.





Blogger comments
You can also set the flag programmatically, should you want to:
[SetUp]
public void Setup()
{
if (Environment.CommandLine.Contains("nunit-console"))
((DefaultTraceListener)Debug.Listeners[0]).AssertUiEnabled = false;
}
After 4 times of copying
[TestFixtureSetup]
public void Setup () { CustomDebugAssert.Disable(); } I got bored and looked for alternatives :)
MbUnit has a [AssemblySetUp] stage which would have been perfect, sadly NUnit doesn't.
Order Finasteride.
Order Tadalafil.TADALAFIL FOR SALE
Order Phentermine 37.5mg
XANAX 1mg.XANAX DISCOUNT.XANAX 2mg.