前端自动化测试karma+mocha+chai

在多人同时改动代码时, 帮助咱们知道是否别的接口或者函数是否是出问题了;javascript

1. Karmahtml

https://karma-runner.github.io/2.0/index.html前端

Karma为前端自动化测试提供了跨浏览器测试的能力;java

 

2. Mochanode

Mocha是前端自动化测试框架;git

支持生命周期;不一样断言库:chai, nodejs的assert, should.js;同步异步;测试分组;等其余框架具有的能力;
github

基本语法:数组

describe('测试1',function(){
    describe('测试1-1',function(){
        it('某个变量的值应该是数字',function(){
            //断言
        })
    });
     describe('测试1-2',function(){
        it('某个数组长度应该不小于10',function(){
            //断言
        })
    });
}) 

生命周期:浏览器

describe('hooks', function() {
  before(function() {
    // runs before all tests in this block
  });
  after(function() {
    // runs after all tests in this block
  });
  beforeEach(function() {
    // runs before each test in this block
  });
  afterEach(function() {
    // runs after each test in this block
  });
  // test cases
});

  

3. Chai框架

Chai是一个断言库合集;

支持语法以下:

expect(bar).to.not.exist;//断言bar不存在
expect(data).to.have.ownProperty('length');//断言data有length属性
expect(name).to.be.a('string');//断言name是一个字符串
assert.equal(value1,value2);//断言value1和value2相等
Tony.should.be.an.instanceof(Person);//断言Tony是Person类的实例
相关文章
相关标签/搜索