最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

JavaScript unit tests: where to keep testspecs files (Client and Node) - Stack Overflow

programmeradmin4浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 17

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

发布评论

评论列表(0)

  1. 暂无评论