16

Possible Duplicate:
Where do the Python unit tests go?

Are unit tests kept in the same file as the code, a separate file in the same directory, or in an entirely different directory?

Jonas Stein
  • 6,826
  • 7
  • 40
  • 72
MKaras
  • 2,063
  • 2
  • 20
  • 35

6 Answers6

15

I always place my unit tests in a subdirectory to the related code called test.

For example: /libs/authentication, the tests would be placed in /libs/authentication/tests

alexn
  • 57,867
  • 14
  • 111
  • 145
5

I prefer to keep them in a seperate directory, usually called either "unittests" or just "tests". I then play games in the Makefile to have to automatically handle this directory, if it exists.

It's a little bit of a pain to set up, but I personally prefer not to have the unit tests cluttering up the functional code. This way they are "close" enough to be obvious, but not in your face all the time.

Chris Arguin
  • 11,850
  • 4
  • 34
  • 50
3

The usual project layout is to have a separate directory with tests, with the tests also subdivided by what they are testing.

Ants Aasma
  • 53,288
  • 15
  • 90
  • 97
0

We keep a separate directory with a parallel class hierarchy. The unit test class name being Test[ClassNameUnderTest]. Should multiple test classes be needed, they are postfixed with an _ and additional text.

Jim Rush
  • 4,143
  • 3
  • 25
  • 27
0

I keep a separate test source tree that mimics the package structure of my source tree.

Example:

/src/main/java/com/xyz/MyClass.java
/src/test/java/com/xyz/MyClassTest.java

With this structure you can test package level methods.

BacMan
  • 436
  • 7
  • 13
-1

for each project there is a test project

Example naming

main project

  • Company.Project.Area

main project testing

  • Company.Project.Area.Test
Kostas Konstantinidis
  • 13,347
  • 10
  • 48
  • 61