Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Mocha.js

Mocha

  • Be the first to comment

Mocha.js

  1. 1. Mocha PEGGY
  2. 2. 軟體測試流程 一、單位測試(Unit Testing):  檢驗每一個單獨的模組是否正確的執行其預期功能,通常用白箱測試 二、整合測試(Integration Testing):  模組結合成子系統,子系統組合成整個系統,因此須檢驗此組合過程與系統的架構 是否正確,通常用黑箱測試 三、驗收測試(Acceptance Testing):  1. α Testing:由使用者在系統開發所在地進行,開發者可觀察使用的情形並記錄。  2. β Testing :在終端用戶之處由使用者自行進行
  3. 3. Mocha  Unit Testing  安裝:npm install mocha
  4. 4. Mocha - Usage  -h, --help output usage information  -V, --version output the version number  -c, --colors force enabling of colors  -C, --no-colors force disabling of colors  -r, --require <name> require the given module  -w, --watch watch files for changes  --compilers <ext>:<module>,... use the given module(s) to compile files  --compilers ts:espower-typescript/guess  --recursive include sub directories  …
  5. 5. Example var assert = require('assert'); describe('Array', function() { describe('#indexOf()', function () { it('should return -1 when the value is not present', function () { assert.equal(-1, [1,2,3].indexOf(5)); assert.equal(-1, [1,2,3].indexOf(0)); }); }); });
  6. 6. Hooks describe('hooks', function() { before(function() { // runs before all tests in this block }); after(function() { // runs after all tests in this block }); beforeEach(function() { // runs before each test in this block }); afterEach(function() { // runs after each test in this block }); // test cases });
  7. 7. assert api  assert(expression, message)  .ok(object, [message]) assert('foo' !== 'bar', 'foo is not bar'); assert(Array.isArray([]), 'empty arrays are arrays'); assert.ok('everything', 'everything is ok'); assert.ok(false, 'this will fail');
  8. 8. assert api  equal(actual, expected, [message])  .deepEqual(actual, expected, [message]) assert.equal(3, '3', '== coerces values to strings'); assert.deepEqual({ tea: 'green' }, { tea: 'green' });
  9. 9. npm power-assert
  10. 10. power-assert  provides descriptive assertion messages through standard assert interface.  available via npm and bower.  supports ES6 through babel plugin, module loader for Traceur Compiler, and module loader for Babel.  supports CoffeeScript.  supports TypeScript.  has TypeScript type definition
  11. 11. power-assert  安裝:npm install mocha –save-dev  var assert = require('assert'); ↓  var assert = require(‘power-assert’);
  12. 12. Compare  assert.equal(-1, [1, 2, 3]);
  13. 13. Compare
  14. 14. Compare
  15. 15. Ref.  http://sunchaoyi.xxking.com/new_page_39.htm  http://www.slideshare.net/t_wada/power-assert-nodefest-2014

×