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
原文地址:https://www.cnblogs.com/rongfengliang/p/8097722.html