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?
Where to put test files. Unit tests run against specific lines of code. So it makes sense to place them right next to that code. Integration tests run against many lines of code in many files.
Use of spec. js is for writing you unit test cases for your angular application. We write test cases in angular using Jasmine & Karma. Jasmine is a Behavior Driven Development testing framework for JavaScript. It does not rely on browsers, DOM, or any JavaScript framework.
js unique: you can write applications in Node. js without the use of external libraries.
Projects 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.com/visionmedia/express
https://github.com/learnboost/mongoose
https://github.com/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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With