一、单元测试作用
个人理解,就是对单个文件进行测试,局部逻辑验证,不用每次整个项目测试。
待测文件:example.go
//example.go
func Add(){
...
}
func InsertMysql(where interface{},interface{}) bool{
}
测试文件命名:example_test.go
//example_test.go
funcTestAdd(t *testing.T){
//给出add函数入参
}
# 二、mock
如果涉及数据库的话,可以用
`gomock.MockGlobalFunc`去mock相关的全局函数
```go
g:= gomock.MockGlobalFunc(example. InsertMysql,func(where interface{},interface{})bool {return false })
defer g.Unpatch()
浙公网安备 33010602011771号