草庐IT

test-dev

全部标签

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 - go 中 dev 和 prod env 的不同 const 值

例如我正在开发留言簿。它允许添加需要主持人批准的记录。但是在开发进一步的功能时,批准在测试期间添加的每条记录是一件很痛苦的事情。那么,是否可以构建应用程序的开发版本来创建带有适当标志集的此类记录?例如prodbuild使用以下函数编译:funcNewRecord()Record{returnRecord{Moderation:Awaiting}}在devbuild中编译:funcNewRecord()Record{returnRecord{Moderation:Approved}}我知道在前端,当你构建一些JS应用程序时,通常的做法是在构建生产时设置NODE_ENV=productio

go - go 中 dev 和 prod env 的不同 const 值

例如我正在开发留言簿。它允许添加需要主持人批准的记录。但是在开发进一步的功能时,批准在测试期间添加的每条记录是一件很痛苦的事情。那么,是否可以构建应用程序的开发版本来创建带有适当标志集的此类记录?例如prodbuild使用以下函数编译:funcNewRecord()Record{returnRecord{Moderation:Awaiting}}在devbuild中编译:funcNewRecord()Record{returnRecord{Moderation:Approved}}我知道在前端,当你构建一些JS应用程序时,通常的做法是在构建生产时设置NODE_ENV=productio

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

testing - 如何在不等待测试的情况下在goroutine中测试结果

我在做golang的时候,有时候需要在goroutine中测试结果,我是用time.Sleep来测试的,请问有没有更好的测试方法。假设我有这样的示例代码funcHello(){gofunc(){//dosomethingandstoretheresultforexampleindb}()//dosomething}然后当我测试func时,我想在goroutine中测试两个结果,我这样做:funcTestHello(t*testing.T){Hello()time.Sleep(time.Second)//sleepforawhilesothatgoroutinecanfinish//te

testing - 如何在不等待测试的情况下在goroutine中测试结果

我在做golang的时候,有时候需要在goroutine中测试结果,我是用time.Sleep来测试的,请问有没有更好的测试方法。假设我有这样的示例代码funcHello(){gofunc(){//dosomethingandstoretheresultforexampleindb}()//dosomething}然后当我测试func时,我想在goroutine中测试两个结果,我这样做:funcTestHello(t*testing.T){Hello()time.Sleep(time.Second)//sleepforawhilesothatgoroutinecanfinish//te