在為 go Test Coverage 測驗 go 檔案時,我在不同的包上運行此命令 -
從這個答案中得到的命令代碼覆寫了不同的包
go test --cover -covermode=count -coverpkg=./app_test/... ./... -coverprofile=cover.out
但它給了我 [build failed]
運行命令后,我的輸出是這樣的 -
go build integration-test/app_test/metadata: no non-test Go files in /home/farhad/GoCodes/GPS-server/integration-test/app_test/metadata
go build integration-test/app_test/ping: no non-test Go files in /home/farhad/GoCodes/GPS-server/integration-test/app_test/ping
go build integration-test/app_test/ID: no non-test Go files in /home/farhad/GoCodes/GPS-server/integration-test/app_test/ID
go build integration-test/app_test/history: no non-test Go files in /home/farhad/GoCodes/GPS-server/integration-test/app_test/history
? integration-test [no test files]
FAIL integration-test/app_test/ID [build failed]
? integration-test/app_test/common [no test files]
FAIL integration-test/app_test/history [build failed]
FAIL integration-test/app_test/metadata [build failed]
FAIL integration-test/app_test/ping [build failed]
? integration-test/domain [no test files]
? integration-test/errors [no test files]
FAIL
如何覆寫不同的包裹?
這是我的包結構 -
├── app_test
│ ├── common
│ │ └── common.go
│ ├── history
│ │ └── history_test.go
│ ├── ID
│ │ └── id_test.go
│ ├── metadata
│ │ └── metadata_test.go
│ └── ping
│ └── ping_test.go
├── data
│ ├── locations.json
│ └── metadata.json
├── docker-compose.yml
├── Dockerfile
├── domain
│ ├── company.go
│ ├── history.go
│ ├── location.go
│ └── metadata.go
├── errors
│ └── rest_error.go
├── ex.txt
├── go.mod
├── go.sum
├── history_config.local.json
├── id_config.local.json
├── main.go
├── Makefile
├── metadata_config.local.json
├── ping_config.local.json
├── README.md
├── run.sh
uj5u.com熱心網友回復:
這似乎是固定在釋放一個問題去1.17.3起由于CMD /去:測驗coverpkg =所有/ ...與測驗只包將無法建立#27333
問題的要點是,如果只有.go像您這樣的測驗包(沒有檔案),則包無法構建。執行緒中建議了幾種解決方法。
解決方法 - https://github.com/golang/go/issues/27333#issuecomment-770200300
我已經在上面發送了一個修復程式,它可能會進入 Go 1.17。在那之前,我同意以前的海報,最簡單的解決方法是通過在這些包中洗掉 no-op 非測驗檔案來避免僅測驗包。例如:
echo "package foo" >foo/foo.go。當上述修復在穩定版本中發布時,可以撤消該解決方法。
uj5u.com熱心網友回復:
我強烈推薦go-acc工具。這就是我們如何進行準確的跨包裝覆寫測量。
所以基本上你只需要這個:
$ goacc ./... -o=coverage.out
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/352826.html
