views:

242

answers:

5

Should unit testing be run in debug or release mode?

I am using Visual Studio Standard Edition 2005 which does not come with any unit testing framework. Since I also do not want to make use of any other 3rd party unit testing framework, I used Debug.Assert to perform the actual test inside all unit test methods. However, Debug.Assert only works in debug mode.

Is there an equivalent in release mode or is there any other alternative (without using 3rd party tools)?

+5  A: 

Do you know that you can define the DEBUG constant in any project configuration? (in Visual Studio, Project properties - Build - Define DEBUG symbol). Or you could define a custom TEST constant (Project properties - Build - Conditional compilation symbols), and create test methods that only run when this constant is defined, by using the Conditional attribute.

Anyway I would say that using a 3rd party testing framework such as NUnit is the most appropriate way for this task, but maybe you have solid reasons for not willing using such tools.

Konamiman
+1 for suggesting to use a proper unit test framework. My personal recommendation would be xUnit.NET.
Mark Seemann
What is the best way to go about defining the debug constant for a particular project?
Lopper
I have expanded the answer explaining that.
Konamiman
A: 

You can actually use Debug.Assert (or Trace.Assert) in a Release config. Check out this article on MSDN for more information.

Personally I don't see a problem with running unit tests on a Debug config. Unit tests are usually aimed at things like logic, not items that are affected by release vs debug, like performance.

popester
+1  A: 

hey check out this

http://blogs.msdn.com/billbar/pages/features-and-behavior-of-load-tests-containing-unit-tests-in-vsts-2008.aspx

As for most of your question, it depends somewhat on what unit testing tool your using. However, in general what you want are preprocessor directives

//C#

ifndef DEBUG

//Unit test

end if

Perhaps for your situation

//C# - for NUnit

if !DEBUG

[Ignore("Only valid for release")]

end if

bala3569
A: 

Using 3rd Party testing frameworks allow you to make sure that can get better code coverage of your code. By being able to write tests to test a method instead of just checking info along the way means that you can test edge cases before they make it out into production.

AutomatedTester
+1  A: 

Don't abuse or butcher Trace.Assert or Debug.Assert for unit testing purposes.

Use a third-party framework.

Wim Hollebrandse