1. Normal case
一般情况我们用的都是
https://pkg.go.dev/testing
指的注意的是,我们可以在TestMain func 里面做一些初始化或者db connection 之类的操作
https://geektutu.com/post/high-performance-go.html
从这里可以了解关于 benchmark
2. BDD Testing, Mocking, and Coverage Analysis
常用的
generate fake API
https://github.com/maxbrunsfeld/counterfeiter/tree/v6.2.1
go run github.com/maxbrunsfeld/counterfeiter/v6 . Stringer

For Mock
https://github.com/vektra/mockery
https://github.com/mockery/mockery

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
ginkgo generate api.go
ginkgo bootstrap

Tips for Go
https://onsi.github.io/ginkgo/
3.Go Test Coverage
https://stackoverflow.com/questions/10516662/how-to-measure-test-coverage-in-go
go get golang.org/x/tools/cmd/cover
go test ./... -cover
go test -cover



本文探讨了Go语言测试的常用方法,包括normalcase下的testing包应用,BDD风格的Mocking与覆盖率分析,以及如何使用Counterfeiter和Mockery进行API模拟。还介绍了GoTest Coverage的测量与提高策略,带你深入了解测试覆盖率工具和实践技巧。
527

被折叠的 条评论
为什么被折叠?



