Keep Debug.Assert windows from halting your Unit Tests

By | November 4, 2013

Debug.Asserts are useful during development, but have you hit a time where one pops during a unit test run? Totally screws up your chi. But what can you do about it, #ifdef them out all over?

Nah. Config file to the rescue!

Head to your unit test project, add an Application Configuration file named app.config

In it, simply put the following:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.diagnostics>
<assert assertuienabled="false"/>
</system.diagnostics>
</configuration>

Or if you already have an app.config for whatever reason, just add the diagnostics area shown here.

This basically just keeps that UI from popping, and keeps your tests chugging right along! As an added bonus, you might be happy to hear that I’ve done this successfully with both nUnit and MSTest unit test frameworks.

  • Sendil Kumar

    Thanks for sharing, wasted good amount of time fixing the problem

    • Brandon

      No problem glad to hear it helped you out! Hope you shared the article w/ your social circle :) #shamelessPlug

  • Kyle Strand

    This seems to prevent my tests from being marked “pass” or “fail” when assertions are triggered (obviously I’d prefer them to be marked “fail”). Is that what you experienced? Any idea how to get the tests to *fail*?