Node.jstestingREST API

我正在testing一个项目,我使用了jasmine framework Node js。

我unit testing客户端代码通过嘲笑$httpBackend

而现在我想testing我的服务器端代码和REST api的,但不知道如何做到这一点?

testingREST API的最佳方法是什么?

我最近为我的REST API应用程序探索了自动化testing,并且遇到了许多技术select。 由于我的REST API基于Express,所以我决定使用同一个开发人员TJ Holowaychuk的testing框架软件,他的testing自己的Express的框架应该做得很好,并且足够满足我的需求。

我对由此产生的Node技术组合感到满意。 我使用Grunt任务运行器(由npm执行),Mochatesting运行器(来自TJ),chai断言库(使用'should'断言样式)和supertest(来自TJ)。

使用该testing堆栈,我可以轻松地运行REST API的自动化testing。 这是一个简单的testing运行时输出:

 [jfathman@cloud api]$ npm test > api@0.0.1 test /home/jfathman/work/git/api > node_modules/.bin/grunt test Running "jshint:file" (jshint) task >> 3 files lint free. Running "mochaTest:test" (mochaTest) task Test API Proxy REST API ? Read config.yaml ? GET /metadata/new, expect json and 200 OK (114ms) ? GET /metadata/saved, expect json and 200 OK (100ms) ? GET /metadata/deleted, expect json and 200 OK (88ms) ? GET /metadata/invalid, expect 400 Bad Request 6 passing (326ms) Done, without errors. 

您也可以单独运行testing运行器:

 [jfathman@cloud api]$ mocha -R spec Test API Proxy REST API + Read config.yaml + GET /metadata/new, expect json and 200 OK (95ms) + GET /metadata/saved, expect json and 200 OK (102ms) + GET /metadata/deleted, expect json and 200 OK (82ms) + GET /metadata/invalid, expect 400 Bad Request 6 passing (305ms) 

在开发过程中从命令行运行REST APItesting套件,或从Jenkins /等运行REST APItesting套件现在是一件简单的事情。 在CItesting期间。

看看Chakram ,它是一个为testingREST API而devise的testing工具。 它写在摩卡顶部,并允许BDD风格。