unittest+coverage单元测试代码覆盖操作实例

更新时间:2023-06-13 00:44:32 阅读: 评论:0

unittest+coverage单元测试代码覆盖操作实例
基于上⼀篇⽂章,这篇⽂章是关于使⽤coverage来实现代码覆盖的操作实例,源代码在上⼀篇已经给出相应链接。
创意之星本篇⽂章字⽤来实现代码覆盖的源代码,整个项⽬的测试框架如下:
就是在源代码的基础上加了⼀个CodeCover.py⽂件,执⾏该⽂件会在⽬录CoverageReport⽣成相应的覆盖报告。如下是CodeCover.py的源码:
#coding=utf8
import os
import time
三年级上册数学题def findTestWithPath():
current_wd()
folderName=os.listdir(current_dir)
#print folderName
电脑名称#获取到测试⽂件所在⽬录
TestSuit=[suite for suite in folderName if  not suite.find("TestSuit")]    #⽤来保存测试⽂件
testfile=[]
还是想念你withPathFile=[]
for suite in TestSuit:
#获取测试⽬录下的所有测试⽂件
testfile=testfile+os.listdir(".\\"+suite)
for withPath in testfile:
withPath=current_dir+"\\"+suite+"\\"+withPath
withPathFile.append(withPath)
del testfile
#把testfile中的py⽂件挑选出来
withPathFile=[name for name in withPathFile if  not "pyc" in name]    #print testfile
print withPathFile
return withPathFile
def codeCoverage():
now = time.strftime("%Y%m%d%H%M")
wd()+"\\"+"CoverageReport"
htmlCmd="coverage html -d  " +  htmlReport +"\\"+now
for pyfile in  findTestWithPath():
心流理论
runPyCmd="coverage run " + pyfile
if ists(htmlReport) :
os.system(runPyCmd)
os.system(htmlCmd)
el:
os.mkdir(htmlReport)
os.system(runPyCmd)
体积密度
相爱到永远os.system(htmlCmd)
if __name__=="__main__":
codeCoverage()
化学九年级运⾏结果图:
转载于:my.oschina/u/2291665/blog/858568

本文发布于:2023-06-13 00:44:32,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/941081.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:测试   覆盖   代码   获取   操作
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图