yhe39 / grunt-test-framework-sample

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Test Framewok Example

a simpe example to describe how to setup the test framework

This example introduces how to use grunt + mocha + chai to take unit test for both nodejs code.

Grunt

is a javascript task runner, is used to control the work flow, plugins are added to it to perform different tasks. Mocha and chai are all enabled by plugins. Links:
http://gruntjs.com/

Mocha

is a nodejs test framework, and also has mocha plugin for grunt. useful links:
https://github.com/mochajs/mocha
http://www.ruanyifeng.com/blog/2015/12/a-mocha-tutorial-of-examples.html
grunt-mocha-test is the plugin for grunt:
https://www.npmjs.com/package/grunt-mocha-test

Chai

Assertion library.

Jshint

could verify js files using static check.
http://jshint.com/docs/
grunt-contrib-jshint is the grunt plugin:
https://www.npmjs.com/package/grunt-contrib-jshint

Jasmine

asmine is a behavior-driven development framework for testing JavaScript code. It does not depend on any other JavaScript frameworks. It does not require a DOM. And it has a clean, obvious syntax so that you can easily write tests. https://github.com/nathanboktae/mocha-phantomjs

Mocha-phantomjs

Run both on Browser and node https://github.com/nathanboktae/mocha-phantomjs

Steps to run

a. download this example and under the directory, npm install all dependencies in the package.json file. You may only need to npm install grunt globally first and then run "npm install" under the directory. b. type "grunt" under the directory. And you will see:
Running "concat:dist1" (concat) task
Running "concat:dist2" (concat) task
Running "jshint:all" (jshint) task

5 files lint free.

Running "mochaTest:test" (mochaTest) task

Test add function
✓ 1+1 = 2 check
✓ -1+1=0 check

2 passing (4ms)

Note: You can also run a single task, for example "grunt concat:dist1" will only take the dist1 test.

About


Languages

Language:JavaScript 79.0%Language:HTML 21.0%