douxu5845 2018-05-08 08:15
浏览 141
已采纳

如何获得文件夹的全局测试覆盖率?

When showing code coverage, go test show code coverage for each package (in percentage).

Is there a way to show a summary for a folder that is taking all subfolder (subpackage) into account?

What I want is a global code coverage percentage for the full project, one number that show code coverage of the folder and all subfolders.

  • 写回答

2条回答 默认 最新

  • dougu1952 2018-05-08 16:25
    关注

    I found a solution to my problem.

    I first run the test on all package and store the test result in a file :

    go test --coverprofile=coverage.out ./...
    

    I then run a bash script to calculate my result

    #!/usr/bin/env bash
    
    covered=0
    total=0
    while IFS='' read -r line || [[ -n "$line" ]]; do
        IFS=' ' read -r -a array <<< "$line"
        total=$(($total+${array[1]}))
        if [ "${array[2]}" = "1" ]; then
            covered=$(($covered+${array[1]}))
        fi 
    done < "$1"
    echo $(awk "BEGIN { pc=100*${covered}/${total}; i=int(pc); print (pc-i<0.5)?i:i+1 }")
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 is not in the mmseg::model registry。报错,模型注册表找不到自定义模块。
  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错
  • ¥25 自动填写QQ腾讯文档收集表