Alex Rivera | Logout

C# - Excluding unit tests from the release version of your project

Asked 2008-09-17T10:22:47.550
24

How do you usually go about separating your codebase and associated unit tests? I know people who create a separate project for unit tests, which I personally find confusing and difficult to maintain. On the other hand, if you mix up code and its tests in a single project, you end up with binaries related to your unit test framework (be it NUnit, MbUnit or whatever else) and your own binaries side by side.

This is fine for debugging, but once I build a release version, I really do not want my code to reference the unit testing framework any more.

One solution I found is to enclose all your unit tests within #if DEBUG -- #endif directives: when no code references an unit testing assembly, the compiler is clever enough to omit the reference in the compiled code.

Are there any other (possibly more comfortable) options to achieve a similar goal?

Edit
Report

2 Answers

1

I've always keep my unit tests in a seperate project so it compiles to it's own assembly.

answered 2008-09-17T10:24:38.280
0

I always create a separate Acme.Stuff.Test project that is compiled separately.

The converse argument is: Why do you want to take the tests out? Why not deliver the test? If you deliver the tests along with a test runner you have some level of acceptance test and self test delivered with the product.

I've heard this argument a few times and thought about it but I personally still keep tests in a separate project.

answered 2008-09-17T11:20:13.123

Your Answer