国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

unittest+coverage單元測試代碼覆蓋操作實例詳解

2020-01-04 15:32:59
字體:
供稿:網(wǎng)友

基于上一篇文章,這篇文章是關(guān)于使用coverage來實現(xiàn)代碼覆蓋的操作實例,源代碼在上一篇已經(jīng)給出相應鏈接。

本篇文章字用來實現(xiàn)代碼覆蓋的源代碼,整個項目的測試框架如下:

unittest,coverage,單元測試

就是在源代碼的基礎上加了一個CodeCover.py文件,執(zhí)行該文件會在目錄CoverageReport生成相應的覆蓋報告。如下是CodeCover.py的源碼:

#coding=utf8 import os import time  def findTestWithPath():   current_dir=os.getcwd()   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")    htmlReport=os.getcwd()+"//"+"CoverageReport"   htmlCmd="coverage html -d " + htmlReport +"//"+now   for pyfile in findTestWithPath():      runPyCmd="coverage run " + pyfile     if os.path.exists(htmlReport) :             os.system(runPyCmd)       os.system(htmlCmd)     else:       os.mkdir(htmlReport)       os.system(runPyCmd)       os.system(htmlCmd)         if __name__=="__main__":   codeCoverage() 

運行結(jié)果圖:

unittest,coverage,單元測試

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識閱讀請移步到python教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 东方市| 麻城市| 津市市| 满城县| 宜都市| 巴林右旗| 昆山市| 崇信县| 化隆| 保亭| 盐亭县| 宝清县| 聂荣县| 犍为县| 揭东县| 张北县| 探索| 谢通门县| 德格县| 尼玛县| 荔波县| 湟中县| 沙坪坝区| 郯城县| 新蔡县| 濉溪县| 勐海县| 出国| 平陆县| 湛江市| 福泉市| 江安县| 九台市| 西和县| 方山县| 江西省| 普陀区| 曲沃县| 革吉县| 盘锦市| 邢台县|