Is it ok to store test file in the location of module itself:
Lets say I have a structure:
project\
module1\
submodule\
submodule.js
submodule.test.js
Or it is better to make a separate location that will repeat the structure of the project:
project\
module1\
submodule\
submodule.js
tests\
module1\
submodule\
submodule.js
I've seen both variants. What considerations should be taken?
Is it ok to store test file in the location of module itself:
Lets say I have a structure:
project\
module1\
submodule\
submodule.js
submodule.test.js
Or it is better to make a separate location that will repeat the structure of the project:
project\
module1\
submodule\
submodule.js
tests\
module1\
submodule\
submodule.js
I've seen both variants. What considerations should be taken?
Share Improve this question asked Sep 26, 2012 at 5:54 WHITECOLORWHITECOLOR 26.1k40 gold badges125 silver badges188 bronze badges1 Answer
Reset to default 17Projects pretty universally keep the tests in a separate location, but don't necessarily repeat the project structure. The test structure is usually flatter than the project structure.
You can see some examples of how people do it at:
https://github./visionmedia/express
https://github./learnboost/mongoose
https://github./mbostock/d3
As to why it is done this way, it makes executing the tests easier since they are all in one folder and makes packaging code easier since the source files and test files aren't intermixed. It also helps when doing things like code coverage builds since you need to instrument all of your source files but don't want to instrument your test code.
In general, whenever I have questions about project structure I just look at popular projects on GitHub and borrow liberally :)