Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS unit test directory structure Best Practices

What is the best practice to follow to create the directory structure for unit tests when using AngularJS for e.g. in general following struct

As mentioned in the link https://scotch.io/tutorials/angularjs-best-practices-directory-structure

What should be the structure to place the unit test files in...if it's an MVC Visual Studio project, should it be in the separate unit test project?

like image 402
shyam_ Avatar asked Feb 03 '15 06:02

shyam_


2 Answers

Putting them side-by-side with the file under test seems to be recommended.

For example:

folder/
  file.js
  file.spec.js
  otherfile.js
  otherfile.spec.js

This recommendation comes from a very good style guide found here: https://github.com/johnpapa/angular-styleguide#style-y197

like image 95
Garry Polley Avatar answered Oct 04 '22 22:10

Garry Polley


According to the Google Best practice which has similar grouping by component you would have the tests in the same folder as the item under test. To keep the same naming convention you would name the tests like homeControllerTest.js or you could use homeController_test.js

like image 44
Wayne Ellery Avatar answered Oct 04 '22 22:10

Wayne Ellery