views:

97

answers:

5

The convention in Java is different - every "module" (equivalent to Java in IntelliJ) has a src and test directory. jUnit can thus run per project, and there's no need for a separate test project.

+2  A: 

Yes - Test classes should go in their own test project.

Colin Mackay
+8  A: 

Yes definitely, you do not want your production assemblies to contain test code (since it is not part of the product as such, but rather part of the development framework around it).

Fredrik Mörk
Thanks David :o)
Fredrik Mörk
Theoretically true, but the test code never gets called (it's just a bunch of classes marked with [TestFixture].
ripper234
Precisely. So it just takes up space, bandwidth, and time (when loading assemblies) for no purpose.
Alexey Romanov
A: 

Yes - you're testing external references. You can be in the same solution, although even that is considered a bit of a shortcut by some purists.

Unsliced
You definitely want them in the same solution, as you need refactoring tools (R#) to work on the test code as well.
ripper234
+3  A: 

As you've probably picked up on, the usual .NET convention is to have the test code in a separate assembly (broadly speaking, in Visual Studio, each Project yields a distinct assembly).

Why is it so?

  • Gives deployment choices
    Many (including I) believe that you shouldn't be deploying tests to production.
  • Limits test access
    Helps to ensure that tests are working against the public interface of the code under test, which increases the need to get your API design right (though sometimes this is a limitation - see Question 261177 for example.)
  • Helps keep each test small
    I used to roll my tests into the same project, but found there was a temptation to reuse too much code, resulting in unit tests that did too much, and were much too brittle.

For what it's worth, I keep my tests in separate projects, though in the same solution, using the [InternalsVisibleTo] attribute as necessary. I name each test as .Tests.dll, and then use a wildcard in a NAnt script to find all the tests to run.

Bevan
A: 

Note: part of the reason you keep tests in the same package in Java is because your tests have to reside in the same package to test package-visible methods. InternalsVisibleTo bypasses this restriction in .Net.

Alexey Romanov