我有以下檔案結構:
? tree
.
├── go.mod
├── go.sum
├── Makefile
├── p1
│ └── p1.go
└── tests
└── integration
└── integration_suite_test.go
3 directories, 5 files
其中,p1/p1.go有一個功能:
? cat p1/p1.go
package p1
func MyTestFunction(s string) string {
return "hello " s
}
我正在從不同目錄的銀杏測驗中進行測驗:
? cat tests/integration/integration_suite_test.go
package integration_test
import (
"testing"
"example.com/test-ginkgo/p1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
func TestIntegration(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Integration Suite")
}
var _ = Describe("Testing external function", func() {
_ = Context("from integration test", func() {
It("and verify coverage", func() {
input := "test"
want := "hello " input
got := p1.MyTestFunction(input)
Expect(got).To(Equal(want))
})
})
})
我通過以下方式執行案例:
$ ginkgo -r -v -race --trace --cover --coverprofile=.coverage-report.out --coverpkg=./... ./...
但是 ginkgo 報告沒有代碼覆寫并且 .coverage-report.out 檔案為空,即使我已指定--coverpkg包含所有目錄。
? cat .coverage-report.out
mode: atomic
我的期望是錯誤的嗎?銀杏不可能實作這樣的跨包覆寫?還是我做錯了什么?--coverpkg似乎在這里沒有做任何有用的事情。
uj5u.com熱心網友回復:
我在 ginkgo repo 中將此作為問題提交,作者非常優雅地向我指出了解決此問題的正確方法。
如下呼叫ginkgo啟動它時,go.mod為引數提到正確的完整路徑(如您的檔案中所述)--coverpkg,它將起作用:
ginkgo -r -v -race --trace --coverpkg=example.com/test-ginkgo/p1 --coverprofile=.coverage-report.out ./...
現在我能夠.coverage-report.out正確地看到包含。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/493240.html
上一篇:Webdriver實體-如何使用一個測驗庫運行多個測驗
下一篇:kotest更改環境變數
