github 之 如何在项目中加入coverage

前言

我们常见github中有代码覆盖率的展示


a. 覆盖率数据只能代表你测试过哪些代码,不能代表你是否测试好这些代码。(比如除零Bug)
b. 不要过于相信覆盖率数据。
c. 不要只拿语句覆盖率(行覆盖率)来考核你的测试人员。
d. 路径覆盖率 > 判定覆盖 > 语句覆盖
e. 测试人员不能盲目追求代码覆盖率,而应该想办法设计更多更好的案例,哪怕对覆盖率无影响。

安装方法

安装见https://github.com/coagulant/coveralls-python

1.First, log in via Github and add your repo on Coveralls website.

2.Add pip install coveralls to install section of .travis.yml

3.Make sure you run your tests with coverage during the build in script part. Example:

# --source specifies what packages to cover, you probably want to use that option
script:
  coverage run --source=yourpackagename setup.py test

Note, that example command will gather coverage for specified package. If you wish to customize what's included in your reports, consult coverage docs.

4.Execute run coveralls in after_success section:

after_success:
  coveralls

5. travis.yml文件
language: python
python:
  - 2.7
  - 3.3
install:
  - pip install -r requirements.txt
  - pip install coveralls
script:
  coverage run --source=moscowdjango,meetup manage.py test
after_success:
  coveralls


可以参照的例子

https://github.com/WoLpH/python-formatter





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值