Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In TDD, is it good practice to keep the tests in the same directory as the code its testing or is it better separate the tests in either a different directory or a separate project.

Would it be the same for a web site where you have the aspx/c# pages in one directory?

share|improve this question
up vote 3 down vote accepted

Test code shouldn't be compiled into the final build. TDD or not, tests belong in a separate directory structure (possibly in the same package) so that the build process can ignore all the tests when building the package.

Keeping tests in the same package, however, allows for some behind the scenes access that tests may need that a public interface doesn't want to provide. There is debate on this point.

As a Java programmer (my apologies, I don't have access to a c#/.net environment), I find that unit testing the huge front end public call with all of the various variables daunting (often involving lots of mocks to get the right objects through to the right tests). Making something protected (rather than private or exposing it to public) means that something in the same package (be it in another directory) will still be able to invoke it.

share|improve this answer
Beware that C# has no equivalent to package-internal access (though it has assembly-internal access). – luiscubal Feb 4 '13 at 22:15

Tests should go into a separate directory. I wouldn't do a separate project because you want the tests to come along when the project is opened.

This way you can deploy only the code into production without having to separate out the tests.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.