Skip to content
This repository has been archived by the owner on Jul 18, 2023. It is now read-only.

Testframework

gasolin edited this page Aug 30, 2014 · 8 revisions

The ideal Test Driven Development process will be:

  1. (setup/teardown env&mockups)
  2. write tests
  3. write code
  4. automation build & test process

SetUp/TearDown Environment and mockups

You can write plain mockup, stubs...etc, or use sinon to ease those tasks. Read public/test/sinon_test.js or slide for more example usage.

To be done

Spy: check is called

var callback = sinon.spy();
.....
assert(callback.Called)

Write test

To be done

Automation build & test process

Test conventions

There are two perspectives to do the test.

You can choose to follow the rules based on your development type (on browser or server-side):

  • files need to be named with test_ prefix

  • (browser test compatibility) make sure include the test_ file and the target file for test in public/test/html

  • (server-side test compatibility) make sure you add this section in each test file:

      if ('undefined' != typeof require) {
        // Require server-side-specific modules
        var chai = require('chai');
        var assert = chai.assert;
      }
    

Thus can fetch required resource in server-side.

2. Browser test

2.1 with browser

Drag and drop public/test/unittest/index.html into browser, and see the test report.

2.2 with command line

Run command

$ grunt mocha_phantomjs

To do the auto browser unit tests.

The client side unit test will be triggered while running grunt pack or grunt static command.

3. Server-side test

The server side unit test will be triggered while running default grunt command. Type

$ grunt

or

$ grunt mochacov

To do the auto server-side unit test.

Complexity report

NOTE: this section is deprecated

Once you run grunt script, the complexity report will be generated into public/test/report folder.

The complexity report includes lines of code, cyclomatic complexity, Halstead complexity measures and the maintainability index.

According to this article, Complexity is measured by the number of paths your code can take. if-else statement for example will add 1 point. If your function is above 10, it's a good idea to refactor it.