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.