zoukankan      html  css  js  c++  java
  • 分享一个一直在用的golang单测小脚本

    [本文出自天外归云的博客园]

    一个名为exec_test.sh脚本,内容如下:

    # 该脚本需要cd到测试文件所在目录下执行
    method=$1
    # 不传入method参数则运行全部测试
    if [ ! -n "$1" ];then
        # 生成测试覆盖率文件
        go test -v -coverprofile=test.out -gcflags=all=-l
        # 生成测试覆盖率html报告
        go tool cover -html=test.out -o test.html
        exit 1
    fi
    # 传入method参数则测试指定方法
    fileList=`ls`
    cmd="go test -v"
    for file in $fileList
    do
        if echo "$file" | grep -q -E '.go$';then
            cmd="${cmd} $file"
        fi
    done
    cmd="$cmd -test.run $method -gcflags=all=-l"
    $cmd

    执行测试的话,就是在待测文件所在目录下调用这个脚本,然后把方法名传进去就可以了,不传方法名执行所有目录下的测试:

    sh exec_test.sh 待测方法名
    sh exec_test.sh

    很好用

  • 相关阅读:
    找零钱「Usaco2006 Dec」
    才艺表演「Usaco2018 Open」
    潜入行动「JSOI2018」
    任务安排「SDOI2012」
    BZOJ2298: [HAOI2011]problem a
    JZOJ 5818
    JZOJ 3493
    JZOJ 3470
    JZOJ 5781
    JZOJ 5778
  • 原文地址:https://www.cnblogs.com/LanTianYou/p/15330609.html
Copyright © 2011-2022 走看看