views:

31

answers:

2

I would like to prevent all subsequent unit tests from running when certain conditions are met in a unit test. Is this possible in Visual Studio 2005?

+1  A: 

This sounds like a code smell. You should set up your unit tests so that they are independent of one another, so that one failing test has no implications on any other tests. It sounds like you are doing something other than true unit testing at the moment.

Paddyslacker
Perhaps I need to clarify what it is I am trying to do. I understand the reasoning behind keeping unit tests independent and my unit tests maintain this rule. What I want to do is run a check to see what environment the unit tests are being run in (Test, QA, PROD) and determine if the unit tests should even run. I thought it would be possible to have the very first unit test (it isn't really a unit test) check the environment and then stop running all subsequent unit tests. If not a unit test, then is there another way to accomplish this?
Sean M. Severson
+1  A: 

This doesn't sound good to me. Unit tests should not have any reliance on ordering.

If you're just trying to save time during a build, consider factoring out the conditional tests into their own assembly and using a build script to determine whether the second set of tests should be run.

womp
Perhaps I need to clarify what it is I am trying to do. I understand the reasoning behind keeping unit tests independent and my unit tests maintain this rule. What I want to do is run a check to see what environment the unit tests are being run in (Test, QA, PROD) and determine if the unit tests should even run. I thought it would be possible to have the very first unit test (it isn't really a unit test) check the environment and then stop running all subsequent unit tests. If not a unit test, then is there another way to accomplish this?
Sean M. Severson
Yes. Your build script should definitely be handling this.
womp