Reputation: 3046
When writing unit tests, do you place your tests inside the assembly you wish to test or in a separate test assembly? I have written an application with the tests in classes in a separate assembly for ease of deloyment as I can just exclude the assembly. Does anyone write there tests within the assembly you wish to test and if so what is the justification for it?
Upvotes: 20
Views: 3405
Reputation: 37378
I have a single solution with an interface project, a tests project, a domain project and a data project. When I release I just publish the interface, which doesn't reference Tests so it doesn't get compiled in.
Edit: The bottom line is really that you don't want it to be part of your final release. You can achieve this automatically in VS by using a separate project/assembly. However you can have it in the same assembly, but then just not compile that code if you're using nant or msbuild. Bit messy though, keep things tidy, use a separate assembly :)
Upvotes: 11
Reputation: 1632
You can keep them in separate assemblies in the solution, and ILMerge them later for debugging, and don't ILMerge them for release.
Upvotes: 0
Reputation: 37103
I'd say that the only time you want to incorporate any test code in your final deployment is when the test code is there for monitoring and control of the application.
Leaving the test code in the deployment:
Decoupling on the otherhand allows you to:
HTH
cheers,
Rob
Upvotes: 10
Reputation: 893
In a different assembly. Otherwise your assembly will reference the test framework (eg Nunit.Framework.dll) and you'll need to install it on the customer machine,
Even if what you ship is a library, and you want your customer to see the unit tests as an example or a specificiation on how to use the objects you provide, there is very little advantage in including in the production assembly.
Upvotes: 5
Reputation: 39500
This is widely debated all over the net.
We use separate assemblies and the InternalsVisibleTo attribute to help the tester assemblies see all the innards of the tested assemblies. We tend to make one test assembly for each assembly we're testing.
Upvotes: 11