testem方便的web tdd 測試框架使用

備註:
   單元測試,對於平常的開發是比較重要的,testem 簡化了咱們的代碼編寫,以及運行。
   主要特性:
   a. 支持的測試框架有:jasmine quint mocha buster.js ,同時也包含一些其餘的適配器,支持
   主流的瀏覽器。
   b. 能夠方便的與持續集成工具進行集成(這個太方便了)。
   c.  跨平臺
   d.  內置 coffeescript  browserify jshint /jslint 的支持
 
1. 安裝
npm install -g testem  or  yarn global add testem (我比較喜歡的方式)
2. 使用
a. 啓動
 testem 
備註:默認啓動端口7357 的網站,能夠試試查看測試信息
b. 一個簡答的測試
touch Usertest.js

describe("firsttest",function(){
  it("consolelogtest",function(){
    console.log("ddd")
   }
  )
})

備註:寫的測試比較簡單,實際上內置了好多方便的斷言庫函數,能夠直接使用
運行界面
 
 
3. 幾個方便的命令
備註:主要是ci 模式
a. testem ci 
b. testem launchers (運行系統能夠用的瀏覽器進行測試)
4. 配置文件( testem.json
格式以下:
{
  "framework": "jasmine",
  "src_files": [
    "hello.js",
    "hello_spec.js"
  ]
}

src_files 支持通配符以下:
{
  "src_files": [
    "js/**/*.js",
    "spec/**/*.js"
  ]
}
5. jenkins 、teamcity 集成插件(基於tap 協議)
jenkins:
https://wiki.jenkins.io/display/JENKINS/TAP+Plugin
teamcity:
https://github.com/pavelsher/teamcity-tap-parser
tap 協議:
http://testanything.org/
6. 擴展
包括配置測試模板、測試處理器、自定義配置測試瀏覽器參數,api proxy 能夠參考官方說明,都是在開發中比較重要的。
7. 參考資料
https://github.com/testem/testem
https://wiki.jenkins.io/display/JENKINS/TAP+Plugin
https://github.com/pavelsher/teamcity-tap-parser
http://testanything.org/
https://github.com/testem/testem/blob/master/docs/config_file.md
相關文章
相關標籤/搜索