草庐IT

Quiz_for_Unit

全部标签

unit-testing - 如何编写When a function having the parameters of c *gin.Context 的测试用例

我正在用golang为我的项目编写Controller的测试用例。在Controller中有函数名称SaveProvider()有参数c*gin.Context我不知道如何将JSON传递给c*gin.Context这个参数以及我如何测试我在Controller中使用的函数谁能告诉我这段代码中的问题是什么。它也称为表驱动测试。packagecontrollersimport("bkapiv1/models""fmt""testing""github.com/gin-gonic/gin")funcTestSaveProvider(t*testing.T){typeargsstruct{c*

azure - 更新 azure-sdk-for-go 库依赖项

执行此任务的最佳做法是什么?到目前为止我尝试过的,只需运行命令depensure-updategithub.com/Azure/azure-sdk-for-go引发了以下错误:Warning:thefollowingproject(s)have[[constraint]]stanzasinGopkg.toml:✗github.com/gravitational/trace.....depensure给我与dep-update命令类似的错误。depcheck给出以下输出:#Gopkg.lockisoutofsync:github.com/Azure/azure-sdk-for-go/ar

unit-testing - 如何在 Golang 中实现 stub ? stub 和模拟之间有什么区别?

关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭4年前。Improvethisquestion我在Golang的单元测试中使用模拟。但是在Golang的实现代码中如何区分stub和mock呢?

arrays - 如何在golang中使用for循环将值存储在结构中

我想将值存储在结构中。我有多个数据集,在迭代这些数据集时,我必须将这些数据集存储到结构中。我还应该拥有以前存储的数据以及当前存储的数据。请找到我正在使用的代码packagemainimport("fmt")typesaveDetailsstruct{IDstringGradestringRegularstringOpeningKeystring}funcmain(){tagsList:=[]saveDetails{}results=[{{1000000001ARegularJOBOp123}}{{1000000002BRegularJOBOp234}}{{1000000003CRegu

unit-testing - 为期望按下的键继续的函数编写 Golang 单元测试

我在Golang中有一个这样的函数:funcExit(codeint){.........keyboard.Open()deferkeyboard.Close()keyboard.GetKey()PrintAndLogInfo("\nBye.")os.Exit(code)}我正在使用以下库来使用此键盘功能github.com/eiannone/keyboard我想为此功能编写单元测试。但是,keyboard.GetKey()需要按下一个键。也许正因为如此,当我运行调用函数Exit的测试时,它失败并显示错误:panic:函数GetKey()应该在Open()之后调用[已恢复]panic:

unit-testing - 如何测试/重构测试调用 http.ListenAndServe 的函数

我正在学习go并且正在开发一个简单的服务,该服务从队列中提取一些数据并将其保存在数据库中。它还运行一个网络服务器以允许抓取数据。现在我有两个go文件(为简洁起见省略了一些文本):funcmain(){parseConfig()s:=&Service{ServiceConfig:config}err:=s.Run()iferr!=nil{panic(err)}}然后是服务的定义(为简洁起见,再次省略了一些部分):func(s*Service)Run()error{iferr:=s.validate();err!=nil{returnerr}iferr:=s.initDB();err!=n

unit-testing - Uber Cadence 事件的单元测试上下文

我正在为使用UUID从联系人服务检索联系人的节奏事件功能编写单元测试。我想知道我应该将什么上下文传递给节奏事件。activity.Register(GetContactActivityFunc)funcGetContactActivityFunc(ctxcontext.Context,inputContactBbInput)(ContactBbOutput,error){...}这是测试函数。funcTestGetContactActivityFunc(t*testing.T){mockCSInterface:=&mocks.Interface{}csClient:=outbound.

go - 限制 VS Code for Go 仅下载 v 1.11 的包

我正在使用VisualStudioCode1.33.1版作为我们的Go应用程序的IDE。我们想为我们的应用程序使用Go版本1.11。但是看起来我们正在使用的一个或多个依赖项已经为Go1.12下载了一个包。现在,VSCode无法构建应用程序并出现以下错误:gobuildgolang.org/x/sys/unix:modulerequiresGo1.12gobuildgithub.com/pelletier/go-toml:modulerequiresGo1.12go[1,1]我尝试重新安装Go1.11,删除有问题的软件包并让它重新安装。无论我何时尝试构建VSCode,下载1.12版本都无

go - 未定义 : SQLiteConn when trying to build go app for armv7

我必须为UbuntuARM-v7编译一个Go服务当我编译它时GOARCH=armGOARM=7gobuild-v-orelease/edge_to_bc-ldflags'-s-w-extldflags"-static"'./...我得到:gitlab.com/company/edge_to_bc/vendor/github.com/hyperledger/fabric/bccsp/pkcs11#gitlab.com/company/edge_to_bc/vendor/github.com/hyperledger/fabric/bccsp/pkcs11vendor/github.com/

go - 如何修复 VS Code 错误 : "Not able to determine import path of current package by using cwd" for Go project

我正在学习教程,我想我可能错过了一些东西。我有一个Go项目位于:/Users/just_me/development/testing/golang/example_server内容是:main.gopackagemainimport"fmt"funcmain(){fmt.Println("hiworld")}我有一个~/go目录。goenv显示:GOPATH="/Users/just_me/go"GOROOT="/usr/local/Cellar/go/1.12.9/libexec"我在VSCode中安装了建议的包。当我保存我的main.go时,我得到:Notabletodetermi