github 之 如何在项目中加入coverage

前言

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

github 之 如何在项目中加入coverage_第1张图片

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





你可能感兴趣的:(github)