草庐IT

test_something

全部标签

testing - 如何在 Go 中使用 gomock 模拟函数?

我是Go的新手,正在做一些简单的小项目+养成测试习惯来学习......但是我在使用mock设置测试时遇到了问题。具体在设置模拟对象sample/sample.gopackagesampleimport("fmt""net/http")funcGetResponse(path,employeeIDstring)string{url:=fmt.Sprintf("http://example.com/%s/%s",path,employeeID)//madesomerequesthere//thenconvertresp.Bodytostringandsaveittovaluereturnv

testing - 如何在 Go 中使用 gomock 模拟函数?

我是Go的新手,正在做一些简单的小项目+养成测试习惯来学习......但是我在使用mock设置测试时遇到了问题。具体在设置模拟对象sample/sample.gopackagesampleimport("fmt""net/http")funcGetResponse(path,employeeIDstring)string{url:=fmt.Sprintf("http://example.com/%s/%s",path,employeeID)//madesomerequesthere//thenconvertresp.Bodytostringandsaveittovaluereturnv

unit-testing - 如何使用 Go 为 App Engine 指定模板路径以进行单元测试?

我在AppEngine上使用带有Go的内置模板包。我有一个处理程序可以将模板呈现给输出。templates:=[]string{"templates/head.html","templates/footer.html"}funcpageIndex(whttp.ResponseWriter,r*http.Request){tpls:=append([]string{"templates/index.html"},templates...)tpl:=template.Must(template.ParseFiles(tpls...))err:=tpl.ExecuteTemplate(w,"

unit-testing - 如何使用 Go 为 App Engine 指定模板路径以进行单元测试?

我在AppEngine上使用带有Go的内置模板包。我有一个处理程序可以将模板呈现给输出。templates:=[]string{"templates/head.html","templates/footer.html"}funcpageIndex(whttp.ResponseWriter,r*http.Request){tpls:=append([]string{"templates/index.html"},templates...)tpl:=template.Must(template.ParseFiles(tpls...))err:=tpl.ExecuteTemplate(w,"

unit-testing - 何时使用 httptest.Server 和 httptest.ResponseRecorder

如题,什么时候使用httptest.Server和httptest.ResponseRecorder?在我看来,我还可以使用httptest.Server测试我的处理程序以返回正确的响应。我可以简单地启动一个由我的处理程序实现提供的httptest.Server,然后对响应的主体进行验证。如有错误请指正,我正在学习Go+TDD 最佳答案 当你只是想检查,如果你的http.Handler做了它应该做的,你不需要使用httptest.Server。只需使用httptest.ResponseRecorder实例调用您的处理程序并检查exa

unit-testing - 何时使用 httptest.Server 和 httptest.ResponseRecorder

如题,什么时候使用httptest.Server和httptest.ResponseRecorder?在我看来,我还可以使用httptest.Server测试我的处理程序以返回正确的响应。我可以简单地启动一个由我的处理程序实现提供的httptest.Server,然后对响应的主体进行验证。如有错误请指正,我正在学习Go+TDD 最佳答案 当你只是想检查,如果你的http.Handler做了它应该做的,你不需要使用httptest.Server。只需使用httptest.ResponseRecorder实例调用您的处理程序并检查exa

go - 不能使用 errors.New ("something wrong") (type error) 作为返回参数中的类型错误

我有以下代码(http://play.golang.org/p/47rvtGqGFn)。它在Playground上工作但在我的系统上失败packagemainimport("log""errors")funcmain(){j:=&JustForTest{}a,err:=j.Test(3)iferr!=nil{log.Println(err)}log.Println(a)}typeJustForTeststruct{}func(j*JustForTest)Test(iint)(string,error){ifi在Playground上,它返回了我预期的东西:2009/11/1023:00

go - 不能使用 errors.New ("something wrong") (type error) 作为返回参数中的类型错误

我有以下代码(http://play.golang.org/p/47rvtGqGFn)。它在Playground上工作但在我的系统上失败packagemainimport("log""errors")funcmain(){j:=&JustForTest{}a,err:=j.Test(3)iferr!=nil{log.Println(err)}log.Println(a)}typeJustForTeststruct{}func(j*JustForTest)Test(iint)(string,error){ifi在Playground上,它返回了我预期的东西:2009/11/1023:00

testing - 使用 go build 但我也看到了 -test 标志

我有一个main.go和mypkg/...go.我用gobuild-omainmain.go或goinstall其中有一些我需要的标志。但我也看到了测试标志。为什么会这样?我错过了什么?Usageof./main:-dockerstringDockerAPIPath,defaultstolocal(default"unix:///var/run/docker.sock")-httptest.servestringifnon-empty,httptest.NewServerservesonthisaddressandblocks-portintThedefaultporttolisten

testing - 使用 go build 但我也看到了 -test 标志

我有一个main.go和mypkg/...go.我用gobuild-omainmain.go或goinstall其中有一些我需要的标志。但我也看到了测试标志。为什么会这样?我错过了什么?Usageof./main:-dockerstringDockerAPIPath,defaultstolocal(default"unix:///var/run/docker.sock")-httptest.servestringifnon-empty,httptest.NewServerservesonthisaddressandblocks-portintThedefaultporttolisten