2015-10-30 15 views
4

我有一個由幾個軟件包組成的庫。當運行測試,我使用「-cover」標誌和顯示每個包individually.Like遵循覆蓋信息:如何在Go中一起獲取所有軟件包的代碼覆蓋率?

--- PASS: TestSampleTestSuite (0.00s) 
PASS 
coverage: 28.7% of statements 
ok  github.com/path/to/package1 13.021s 
?  github.com/path/to/package2 [no test files] 

=== RUN TestAbc 
--- PASS: TestAbc (0.43s) 
PASS 
coverage: 27.7% of statements 

有什麼辦法可以輕鬆地獲得了全覆蓋的概述,以獲取有關報道好主意在整個項目上?

更新:這是我使用

go test ./... -v -short -p 1 -cover 
+0

能否請編輯您的帖子包含了'去test'命令與你的論點? –

+0

好的,完成!讓我知道它是否有幫助。 – Rana

回答

1

這裏去測試命令從https://github.com/h12w/gosweep提取的bash腳本:

#!/bin/bash 
set -e 
for dir in $(find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -type d); 
do 
if ls $dir/*.go &> /dev/null; then 
    go test -short -covermode=count -coverprofile=$dir/profile.tmp $dir 
    if [ -f $dir/profile.tmp ] 
    then 
     cat $dir/profile.tmp | tail -n +2 >> profile.cov 
     rm $dir/profile.tmp 
    fi 
fi 
done 

go tool cover -func profile.cov 
+0

那麼,它仍然顯示每個軟件包的覆蓋率信息,這是我從給定的命令得到的。任何調整來獲得整體覆蓋信息? – Rana

+0

它輸出的最後一行是這樣的:'總數:\t(語句)\t \t 99.3%',那是不是你想要的@Rana? – HectorJ

+1

這給我一個「壞模式行」的錯誤。 –