0

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
  • 8
    why don't you want to rely on any 3rd party unit testing framework? Commented Dec 11, 2009 at 8:08
  • 4
    And I would like to make some toast, but without a toaster. Commented Dec 11, 2009 at 8:17
  • @Gregory: Mostly because I would like to reduce the dependency of the code on other 3rd party framework to a minimum. This holds true for both the production code and the unit testing code. If I am using a version of Visual Studio with unit testing framework built in, then I wouldn't mind using it. Commented Dec 11, 2009 at 8:30
  • 1
    @Lopper It's very much accepted in our profession that we need third-party libraries for things we don't want/need to roll ourselves. That's the whole reuse argument. Sounds like a case of 'not-invented-here' syndrome. Commented Dec 11, 2009 at 8:43
  • 1
    You're being too cautious. NUnit is tried and tested.. Rolling your own unit testing framework isn't the best use of your time. Also it shouldn't matter if you run tests with either debug/release, for a given snapshot of code and tests, the results should be consistent. Commented Dec 11, 2009 at 8:44

5 Answers 5

7

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 to use such tools.

Sign up to request clarification or add additional context in comments.

3 Comments

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

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

Use a third-party framework.

Comments

1

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

Comments

0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.