我有以下文件结构:
❯ 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=./... ./...
--coverpkg
❯ cat .coverage-report.out
mode: atomic
--coverpkg