Debug vs. Unit Testing

I was hoping to get some opinions about using the System.Diagnostics.Debug class instead of or in addition to NUnit unit testing.
What do other developers favor more, Unit Testing or Debug
Also what are your thoughts on using the Trace class with TraceListeners to implement logging of an application, say versus using a framework like log4Net
Thanks.



Answer this question

Debug vs. Unit Testing

  • Binu Jeesman

    Thanks for the good info guys.

  • Sweeps78

    There is no way you can substitute unit testing for simple use of the Debug class (I'm assuming you mean use of Debug.Assert here ). This is useful for checking that you are in the right state within a class, but does not act as a test driver. You need to unit test to try and create the conditions that could cause your assertions to fail.

    I tend to use Debug.Assert for checking the parameters of private methods, as the public/protected/internal ones should have already done the checking, so I don't want the runtime overhead of additional checks. This means I can unit test and where I have failed to correctly construct a parameter to a private method I will be warned of it.

    The other place I tend to use it is when managing complex state such as a number of collections or in an algorithm. In this case I tend to litter Debug.Assert around to check the state of the object so I know immediately it has gone wrong, but without incurring any runtime overhead when the testing is complete and the final version is released.



  • Saania

    Agree with Greg.

    I like the Logging Application Block (part of Enterprise Library) for logging. Internally, it uses tracelisteners, etc, but offers a simple user interface with a pretty robust configuration utility.


  • Laughing John

    You must first find the bugs before you can debug them. So testing is to find bugs, debug is to find out where the bugs really are in your code/design.

  • Debug vs. Unit Testing