亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

go 測試在提供 -coverpkg 參數時失敗

go 測試在提供 -coverpkg 參數時失敗

Go
炎炎設計 2022-08-24 18:43:52
我正在嘗試在我的項目中的所有包中獲得測試覆蓋率。測試成功執行,并在執行以下命令時報告覆蓋范圍。go test -cover ./...但是當我使用參數執行時,所有測試都失敗了go testcoverpkg=./...go test -cover -coverpkg=./... ./...這是命令的示例輸出srimal@srimal-pc:~/projects/myproject$ go test -v -cover -coverpkg=./... ./...go build a.abc.com/path/to/module/e2e: no non-test Go files in /home/srimal/projects/driver-selection-handler/e2e?       a.abc.com/path/to/module      [no test files]?       a.abc.com/path/to/module/app  [no test files]?       a.abc.com/path/to/module/constrain    [no test files]FAIL    a.abc.com/path/to/module/directionalhire [build failed]?       a.abc.com/path/to/module/domain       [no test files]FAIL    a.abc.com/path/to/module/durationmatrix [build failed]FAIL    a.abc.com/path/to/module/durationmatrix/etaservice [build failed]FAIL    a.abc.com/path/to/module/durationmatrix/roadmatrix [build failed]2021/04/22 17:23:07 go-util/log: Cannot open config file  open config/logger.yaml: no such file or directorytesting: warning: no tests to runPASScoverage: 0.0% of statements in ./...ok      a.abc.com/path/to/module/e2e  (cached)        coverage: 0.0% of statements in ./... [no tests to run]?       a.abc.com/path/to/module/events       [no test files]FAIL    a.abc.com/path/to/module/finance [build failed]?       a.abc.com/path/to/module/internal     [no test files]?       a.abc.com/path/to/module/internal/config      [no test files]?       a.abc.com/path/to/module/internal/logger      [no test files]?       a.abc.com/path/to/module/internal/metrics     [no test files]?       a.abc.com/path/to/module/internal/profiling   [no test files]?       a.abc.com/path/to/module/internal/schema      [no test files]?       a.abc.com/path/to/module/internal/stream      [no test files]我使用的是 go 版本 1.15.6有沒有辦法找到構建失敗的原因?
查看完整描述

2 回答

?
肥皂起泡泡

TA貢獻1829條經驗 獲得超6個贊

有沒有辦法找到構建失敗的原因?

單獨生成(或測試)包。


查看完整回答
反對 回復 2022-08-24
?
慕運維8079593

TA貢獻1876條經驗 獲得超5個贊

我沒有直接的答案,但我遇到了類似的問題,也許我的過程可以幫助您解決問題。


首先,是你的朋友。Go 文檔、參考和 Go 一般都是關于提高你的工作效率。因此,Go團隊投入了大量精力來解釋好事情。go help


go help test是開始獲取有關標志信息的好地方,但它沒有列出 .然而,它確實指出:-coverpkggo help testflag


測試二進制文件還接受控制測試執行的標志;這些標志也可以通過“go test”訪問。有關詳細信息,請參閱“轉到幫助測試標志”。


go help testflag有這樣說的:-coverpkg


-coverpkg pattern1,pattern2,pattern3

    Apply coverage analysis in each test to packages matching the patterns.

    The default is for each test to analyze only the package being tested.

    See 'go help packages' for a description of package patterns.

    Sets -cover.

強調“默認是每個測試僅分析正在測試的包”,這意味著如果我依賴于包函數,如果我逐個包地工作,我可能會遇到問題。init()


如果你想遵循單獨運行每個包的建議,你可以在模塊的根目錄中使用獲取所有包的列表,然后使用一些shell腳本來循環訪問它們。coverpkggo list ./...


最終,在我的情況下,我推斷出這是逐個測試每個包,因此可能逐個加載包。因此,我能夠將問題范圍縮小到包的功能。不知道為什么它會導致問題,但是從函數中移出幾行可以進入函數,解決了我的問題。-coverpkginit()init()main()


(我也很幸運,錯誤消息很容易谷歌,我知道它與CLI標志解析有關。請參閱在測試文件中使用主銷)


查看完整回答
反對 回復 2022-08-24
  • 2 回答
  • 0 關注
  • 209 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號