Thursday, December 18, 2008

Trace.Assert

In nunit or other test framework, we have Assert object to test whether result is as expected. If assert is false, then en exception is through. Trace.Assert is provide similar function, but for different purpose. It is for diagnostic. When assert is false, it output the error message to a listener. There is default listener in .net, which is DefaultTraceListener An instance of this class is automatically added to the Debug..::.Listeners and Trace..::.Listeners collections. Explicitly adding a second DefaultTraceListener causes duplicate messages in the debugger output window and duplicate message boxes for asserts. The DefaultTraceListner looks like throwing an exception, but it is not actually an exception, it is the output behavior. If you remove the DefaultTraceListner, you will not see this output.

No comments:

Post a Comment