Giter VIP home page Giter VIP logo

coverage's Introduction

ReadMe

Build Status Coverage Status

coverage

如何给自己的项目增加测试覆盖率

步骤

  • 安装 mocha
npm install mocha -g
  • 安装断言库 should
npm install should --save-dev
  • 编写测试用例
let should = require('should');

function add(x, y){
	return x + y
}

describe('sum', function() {
    describe('#add()', function() {
        it('1 add 2 should equal 3', function() {
            add(1, 2).should.equal(3);
        });
        it('4 add 5 should equal 9', function() {
            add(4, 5).should.equal(9);
        });
    });
});
  • 执行 mocha 测试用例通过

  • 安装 node 环境下的 测试覆盖率库 Istanbul

  npm install istanbul -g
  • 安装mocha 的测试报告输出库 mocha-lcov-reporter
  npm install mocha-lcov-reporter --save-dev
  • 先在本地执行
  istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly
  • 安装 node-coveralls coveralls 的作用是 收集istanbul生成的测试数据 发送到 coveralls.io这个网站显示你的 覆盖率
 npm install coveralls --save-dev
  • 打开 travis-ci.com/(存放自己的private 仓库) 并用github 帐号做认证 然后 travis-ci.org(这个存放资金的public 仓库) 添加需要 build的 repo

  • 添加.travis.yml 在自己的项目根目录下

language: node_js
node_js:
  - "6"  
before_install: 
  npm install -g mocha
  npm install -g istanbul
  • 开始 push 代码 并触发 ci build

  • 打开 coveralls.io/ 用github 帐号做认证然后同步数据 添加要显示覆盖率的repo

  • 在 package.json 文件中 增加

 "scripts": {
    "test": "mocha",
    "cove":"istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
  } 
  • 在 .travis.yml 中添加 最后执行测试覆盖率
  after_script:
     npm run cove  
  • 再次push build 完成并且数据提交成功以后 在coveralls.io网站中自己的仓库中就会显示出 覆盖率

  • 添加 badge(勋章)

   在 Readme 中添加
   [![Build Status](https://travis-ci.org/xiaolong2013/coverage.svg?branch=master)](https://travis-ci.org/xiaolong2013/coverage.svg?branch=master)
   [![Coverage Status](https://coveralls.io/repos/github/xiaolong2013/coverage/badge.svg?branch=master)](https://coveralls.io/github/xiaolong2013/coverage?branch=master)

参考

coverage's People

Contributors

xiaolong2013 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.