安装gomock:
go get github.com/golang/mock/gomock
go get github.com/golang/mock/mockgen
使用 mockgen 生成 mock 代码: 参考
mockgen -source=service/user.go -destination=service
/mocks/mock_user_service.go -package=mocks
go test -coverprofile=coverage.out && go tool cover -func=coverage.out
go test -coverprofile=coverage.out ./... &&
go tool cover -func=coverage.out | grep treasury.go
测试单个文件
go test -coverprofile=coverage.out ./... &&
go tool cover -func=coverage.out | grep treasury.go