执行
命令
gulp master
结果
? SuperTestWithGulp git:(master) gulp master
[17:34:44] Using gulpfile ~/Downloads/SuperTestWithGulp/gulpfile.js
[17:34:44] Starting 'master'...
[17:34:44] Finished 'master' after 37 ms
You are in master
Test Demo.
? Visit http://aimer1124.github.io/ (502ms)
1 passing (506ms)
结果分析:? Visit http://aimer1124.github.io/ (502ms)表示测试正常通过;1 passing (506ms)表示整个测试所执行的时间和测试所执行的数量
自动化测试的持续集成
持续集成是什么
Continuous Integration (CI) is a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.
Travis CI
在线CI工具
官网:https://travis-ci.org/
Travis与Gulp集成
使用Git项目SuperTestWithGulp
在项目根目录中添加.travis.yml文件,language表示使用的语言为node_js,0.12表示使用node_js的版本,before_script表示运行脚本前执行的脚本命令,script表示启动时的执行脚本
language: node_js
node_js:
- "0.12"
before_script:
- npm install -g gulp
script: gulp master
在Travis中关联此Github项目SuperTestWithGulp
Travis会在Github代码有变更时,自动拉取项目的代码并进行在线集成
Jenkins
Build great things at any scale
官网:https://jenkins.io/
Jenkins与Grunt集成
安装NodeJS、Git插件
配制Job的build step中execute shell
运行Job即可执行API测试
总结
API自动化测试已经说完了,完全没有太复杂的代码和编写难度。
使用SuperTest可实现多场景、多环境的API场景测试,且执行速度较UI自动化测试快很多。
SuperTest与Grunt/Gulp的集成很方便,即使在本地进行调试也很快捷。
持续集成工具Travis/Jenkins,与API测试集成后,更高效的提高测试效率。