API自動化測試與持續集成

啄木鳥軟件測試培訓網:www.3testing.comgit

 目的github

  · 如何使用SuperTest測試框架,進行API測試npm

  · 如何將API測試與構建工具結合json

  · 如何將API測試、構建工具與持續集成結合gulp

  SuperTest微信

  什麼是SuperTest框架

  To provide a high-level abstraction for testing HTTP,提供一個高級別的HTTP測試ide

  Github地址:SuperTestgrunt

  如何安裝工具

  · 命令

  npm install supertest --save-dev

  · 樣例

  describe('Test Demo.', function() {

  it('Visit URL', function(done) {

  request.get('')

  .expect(200)

  .end(done);

  });

  });

  · 樣例原理:經過獲取請求的結果,對請求結果進行驗證。樣例中的驗證條件爲返回的狀態碼爲200。

  自動化API測試:Grunt & Gulp

  Grunt篇

  什麼是Grunt

  · The JavaScript Task Runner,JavaScript的構建工具

  · 官網:Grunt

  安裝

  · 命令

  npm install -g grunt-cli

  功能分析

  測試目的:請求https://github.com/aimer1124/SuperTestWithGrunt是否能返回狀態碼200

  使用Github來Clonehttps://github.com/aimer1124/SuperTestWithGrunt.git

  

  · /test/module/demo.js:測試腳本

var config = require('../config/endpoints'),

request = require('supertest')(config.host[config.env]);

describe('Test Demo.', function() {

this.timeout(10000);

it('Visit ' + config.env, function(done) {

request.get('')

.expect(200)

.end(done);

});

});

  · /test/config/endpoints.js:環境配製

module.exports = {

host : {

master: 'https://github.com/aimer1124/SuperTestWithGrunt',

branch: 'https://github.com/aimer1124/SuperTestWithGrunt/tree/differentENV'

},

env: process.env.NODE_ENV || 'master'

};

  · Gruntfile.js:Grunt運行時的命令配製

  · package.json:npm 安裝時所須要的包

  · results.txt:執行結果存放文件

  執行

  · 命令:grunt

  · 運行結果

SuperTestWithGrunt git:(master) ? grunt

Running "mochaTest:test" (mochaTest) task

Test Demo.

Visit master (1640ms)

1 passing (2s)

Done, without errors.

  結果分析:Visit master (1640ms)表示測試正常經過;1 passing (2s)表示整個測試所執行的時間和測試所執行的數量

  Gulp篇

  什麼是Gulp

  · Automate and enhance your workflow,自動化而且加強你的工做

  · 官網:http://gulpjs.com/

  · 中文官網:http://www.gulpjs.com.cn/

  安裝

  · 命令

  npm install --global gulp-cli

  功能分析

  測試目的:請求http://aimer1124.github.io/是否能返回狀態碼200

  使用Github來Clonehttps://github.com/aimer1124/SuperTestWithGulp

  

  · /test/config/endpoints.js:環境配製

  var host = {

  master: require('./master.js'),

  branch: require('./branch.js')

  };

  var ENV;

  module.exports = function(env) {

  if (env) {

  ENV = host[env];

  return;

  }

  return ENV;

  };

  · /test/config/master的具體配製

  module.exports = {

  url: 'http://aimer1124.github.io/',

  name: 'master'

  };

  · /test/module/test-demo.js:測試腳本

  var data = require('../config/endpoints'),

  request = require('supertest')(data().url);

  describe('Test Demo.', function() {

  this.timeout(10000);

  it('Visit ' + data().url, function(done) {

  request.get('')

  .expect(200)

  .end(done);

  });

  console.log('You are in ' + data().name);

  });

  gulpfile.js:Grunt運行時的命令配製

  package.json:npm 安裝時所須要的包

  results.txt:執行結果存放文件

顧翔凡言:

想作軟件測試,最好先去作兩到五年開發

啄木鳥軟件測試培訓中心,主打五門課:

初級:

1,你也想成爲軟件測試工程師嗎~軟件測試基礎教程

中級:

2,軟件測試工程師必須掌握的技能~軟件測試設計方法實戰。

高級:

3,讓你的程序跑得更快~軟件性能測試

4,讓你找出更多的bug~探索式軟件測試

5,讓用戶迷上你的產品~用戶體驗式測試


本文分享自微信公衆號 - 軟件測試培訓(iTestTrain)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。

相關文章
相關標籤/搜索