DIV CSS 佈局教程網

用 Node.js 與 testosterone 做 Function Test
編輯:關於JavaScript     

為什麼用 Node.js 做功能測試

功能測試不一定要使用沉重的 Java 專案。若測試對象是 HTTP API,用 Node.js 撰寫測試會更輕量,也更接近前端開發者的語 habit。

建立測試伺服器

可以先用 Express 建立幾個簡單的 GET 與 POST 端點,例如 /hello、/user 與 /user/edit,作為測試對象。

撰寫測試案例

testosterone
  .get('/hello', function (res) {
    assert.equal(res.statusCode, 200);
  })
  .get('/user/1', function (res) {
    var user = JSON.parse(res.body);
    assert.equal(user.name, 'node js');
  });

優點

這種寫法語意清楚,測試案例容易閱讀。相比冗長的 HTTP 設定,testosterone 這類工具能讓測試流程更簡潔。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved