Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit testing directory structure

Tags:

unit-testing

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.

like image 695
zachary Avatar asked May 11 '10 18:05

zachary


2 Answers

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.)

like image 141
Bill the Lizard Avatar answered Sep 23 '22 02:09

Bill the Lizard


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.

like image 37
philant Avatar answered Sep 23 '22 02:09

philant