草庐IT

test_dict

全部标签

unit-testing - 获取数据库连接的连接字符串

我正在尝试测试这个功能://OpenConnectionopensaconnectiontoaMySQLdatabaseby`connStr`//orreturnserror.If`connStr`isempty,errorisreturned.////Parameters://-`connStr`:theURLofthedatabasetoconnectto//-`interpolateParams`:shouldweinterpolateparameters?////Returns://-pointertothedatabaseconnection//-anyerrorsthath

unit-testing - 在辅助函数中包装 httptest 方法

在我的处理程序测试中,我多次使用header中带有身份验证token的测试请求服务模式。为了对此进行抽象,并为自己节省大量行数,我编写了以下函数:funcserveTestReq(payloadstring,routestring,methodstring,handlerfuncfunc(whttp.ResponseWriter,r*http.Request),tokenstring){body:=strings.NewReader(payload)req,err:=http.NewRequest(method,route,body)Expect(err).NotTo(HaveOccu

unit-testing - 如何在 golang 中编写关于插入、获取、删除和更新数据的测试用例

我必须编写插入、获取、删除和更新数据的测试用例。在互联网上搜索时,我找到了一个代码并且它可以工作,但我不知道它是如何工作的。我的代码在下面给出,任何人都可以用简单的方式告诉我我将如何理解代码。packagemodelsimport("testing""gopkg.in/mgo.v2/bson""fmt")funcTestAddBlog(t*testing.T){typeargsstruct{queryinterface{}}tests:=[]struct{namestringargsargswantbool}{{"first",args{bson.M{"_id":4,"title":"

unit-testing - 在 Go-kit 中为 make 处理函数编写单元测试

我的问题特定于Go-kit以及如何在其中组织代码。我正在尝试为以下功能编写单元测试:funcMakeHandler(svcService,loggerkitlog.Logger)http.Handler{orderHandler:=kithttptransport.NewServer(makeOrderEndpoint(svc),decodeRequest,encodeResponse,)r:=mux.NewRouter()r.Handle("/api/v1/order/",orderHandler).Methods("GET")returnr编写适当的单元测试的正确方法是什么?我见过

unit-testing - 如何定义模拟方法被调用零次

我正在尝试测试以下方法://AuthenticationMiddlewareMiddlewarewhichhandlesalloftheauthentication.funcAuthenticationMiddleware(contextcontext.ContextIntf,wweb.ResponseWriter,r*web.Request,nextweb.NextMiddlewareFunc){//Checkifurlisonethatdoesn'tneedauthorization.Ifnotthansendthemtotheloginpage.for_,url:=rangeAu

unit-testing - 如何重写gocov命令去工具覆盖?

我有以下命令:${GOPATH}/bin/gocovtest./...2>test|${GOPATH}/bin/gocovreport如果我使用gotoolcover,这个命令会是什么样子? 最佳答案 自go1.10gotoolcoverage支持递归包绕过gotest./...-coverprofile=coverage.out 关于unit-testing-如何重写gocov命令去工具覆盖?,我们在StackOverflow上找到一个类似的问题: http

unit-testing - 以 http 作为包装函数的依赖项的单元测试

我有以下函数,在@poy的帮助下,我能够为它创建模拟以便对其进行单元测试。现在的问题是我有包装函数也需要测试这是原始函数,已经过测试funchttpReq(cc[]string,methodstring,urlstring)([]byte,error){httpClient:=http.Client{}req,err:=http.NewRequest(method,url,nil)iferr!=nil{returnnil,errors.Wrap(err,"failedtoexecutehttprequest")}//Herewearepassinguserandpasswordreq.

unit-testing - 如何在 ReverseProxy 中测试 header ?

我正在尝试对以下代码进行单元测试:func(h*Handler)Forward(whttp.ResponseWriter,r*http.Request){url,err:=url.Parse("http://test.com")iferr!=nil{return}reverseProxy:=&httputil.ReverseProxy{Director:func(r*http.Request){r.URL.Host=url.Hostr.URL.Path="/"r.URL.Scheme=url.Schemer.Host=url.Hostr.Header.Set("X-Forwarded-

go - 如何在运行 'go test' 时排除或跳过特定目录

这个问题在这里已经有了答案:Runningtestsandskippingsomepackages(1个回答)关闭3年前。gotest$(golist./...|grep-v/vendor/)-coverprofile.testCoverage.txt我正在使用上面的命令来测试文件,但是我想从测试中排除1个名为“Store”的文件夹。怎么做到的?

unit-testing - 表驱动测试中的竞争检测

我有一个表驱动测试和表循环外的initvar(worker)。我使用gotest-raсe运行测试并添加了t.Parallel()并且没有检测到竞争条件。我可以假设我的测试没有竞争条件吗://Thismockcouldbeinaseparatefile.typemockWorkerstruct{}//implmentourWorkeriterfacefunc(mdmockWorker)Work()error{returnnil}typemockDoerstruct{ErrorerrorWorkerworker}//implmentourDoeriterfacefunc(mdmockDo