tags:

views:

102

answers:

2

Huge project tons of classes and directories.

Do I make my unit test project mirror these directories or do I put them all at the root directory?

Somewhat annoying to have to make directory changes and class name changes twice.

+8  A: 

You definitely want your unit test directories to mirror the directories of the code under test. It's a mild pain to set up manually, but that pain doesn't last nearly as long as the pain of having all your tests in a pile, or even worse, having them in some different structure than the code under test.

Evidently you're not using Java, or your test code would already have the same package structure as the code under test and the question would be moot. (At least I can't imagine doing it any other way.)

Bill the Lizard
Seconded. Any decent IDE will make refactoring directories and names easy as well.
Jherico
Depending on the language, I would put more stress on packages/modules/namespaces rather than directories.
Gabriel Ščerbák
@Gabriel: I agree. I wanted to do that, but @zachary didn't specify a language.
Bill the Lizard
@Bill the Lizard: what would you suggest for a namespace structure in c#/.NET? I've currently mirror the namespaces of the code under test (e.g. a test for method Product.Domain.Customer.Method() is Product.Tests.Domain.Customer.Method.TestName()) to keep it logical, but there often becomes compile-time ambiguities that almost make it not worthwhile.
SnOrfus
A: 

I'd favor having the unit tests in the project directory, to keep them physically close to the code they are supporting. The directory containing the unit tests for one component/package being in that component/package directory, in a specific test directory, at the same level as the src directory. This is what I'm doing for C/C++ projects FWIW. The main reason is to be able to compile the component and its unit tests at the same time, to make the unit tests visible (our legacy components do not all have unit tests).

That way, every change made to the directory structure does not have any impact on the test directories structure, as the unit tests are moved along with the production code. Having two parallel directories structures is a form a duplication to me.

philippe