zoukankan      html  css  js  c++  java
  • 前端自动化测试karma+mocha+chai

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

    1. Karma

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

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

    2. Mocha

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

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

    基本语法:

    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类的实例
    

      

    欢迎指正批评!!!
  • 相关阅读:
    vscode如何将less编译到指定css目录中
    md文档的书写《二》
    关于页面scroolTop的获取
    git学习 c的某位老哥的,(侵删)
    学习git使用网址
    git,github,gitlab,码云的区别
    Git的基本使用
    php_review_day1
    shell脚本编程基础-构建基本脚本
    Linux基本命令
  • 原文地址:https://www.cnblogs.com/ljyqd/p/11905437.html
Copyright © 2011-2022 走看看