当前位置: 首页 > 工具软件 > Convey > 使用案例 >

go之测试工具(goconvey、gostub、gomock...)

笪昌翰
2023-12-01

1、gostub

  • 包引用
go get github.com/prashantv/gostub
  • 使用
//函数重构
var stubedFunc=func()

//为函数打桩
stubs := StubFunc(&stubedFunc,......)
defer stubs.Reset()

2、go test

  • go test 默认执行当前目录下以xxx_test.go的测试文件。
  • go test -v 可以看到详细的输出信息。
  • go test -v xxx_test.go 指定测试单个文件,但是该文件中如果调用了其它文件中的模块会报错。
  • go test -v xxx_test.go Testxxx   指定某个测试函数运行
  • go test -cover ./... 测试覆盖率
 类似资料: