Nunit and standard assertion
If you use Nunit and use standard System.Diagnostics.Debug.Assert in your code, you can get tired of the messagebox that is raised when a standard assertion fail. To avoid this, you can use app.config to completely remove all listener during the test.
|
|
This solves the problem, now you can launch nunit interface, run the test and get rid of the annoying messagebox that gets displayed when a standard assertion fail. If you do not want to use app.config, you can still create a base test class, and clear the listeners in the fixture setup.
|
|
With this code you get the same effect, except that now you can disable listeners per test instead of disabling for entire test suite.
This technique has a drawback, in this way you completely disable standard assertions, but I like that my tests fail even if a standard assertion fails, and it is good to make possible for me to choose if in a test I want that standard assertion make my test fail or not. A quick and dirty solution is the following
|
|
This class inherits from standard TraceListener, standard messages goes to the console (nunit is able to intercept them) and I override the two Fail() method that are called when some assert is failing. In my fail routines I simply make a standard fail assertion of nunit framework, this makes my test fail. The only thing you need to do is to set this listener in the trace.listeners collection
|
|
alk.
Tags: nunit TraceListener