草庐IT

parameterized-tests

全部标签

unit-testing - 标准库错误的覆盖率测试

我一直在尝试了解Go的内置测试框架并获得适当的测试覆盖率。在我正在测试的其中一个文件中,我只获得了大约87%的覆盖率:覆盖率:87.5%的语句下面是测试中的部分代码://Checkthattheworkingdirectoryissetif*strctFlags.PtrWorkDir==""{//iftheworkingdirectoryisempty,setittothecurrentdirectorystrTemp,err:=os.Getwd()iferr!=nil{return"",errors.New("Couldnotgetcurrentworkingdirectory")}

testing - 如何测试延迟的 Go 语句?

如何测试doStuff函数?(Playground:http://play.golang.org/p/aPFSlaBLgX)packagemyPackagevarlocked=falsefuncdoStuff(){deferunlock()lock()//sometaskthatcancauseerrors//needtotestiflockwasreallyunlocked//thisisjustasimpleexample,thingscangocomplexonrealworldpanic("!")}funclock(){locked=true}funcunlock(){lock

go - 使用 go test 时出现身份验证错误

我在设置exportGO111MODULE=on后使用gotest命令更新go.mod并运行测试套件。我看到很多像下面这样的身份验证错误Theauthenticityofhost'gitlab.com(35.231.145.151)'can'tbeestablished.ECDSAkeyfingerprintisSHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw.Areyousureyouwanttocontinueconnecting(yes/no)?Theauthenticityofhost'gitlab.com(35.231.14

testing - 如何使用相对目录测试 Go 程序?

来自测试文档:“该包构建在一个临时目录中,因此它不会干扰非测试安装。”因此,任何使用与可执行文件相关的目录的代码都不会相对于Temp\go-build出现......换句话说,给定以下内容:.\helloplanet.go.\行星\行星.res.\helloplanet_test.gogotest在Temp\go-build中生成一个exe...但它不会在那里重新创建一个planets\子目录,因此在helloplanet.exe中寻找planets\planetary.res的任何代码当然不会找到该如何应对? 最佳答案 这是一个实

python - 运行 py.test 时出现错误 ImportMismatchError

当我在本地运行测试时,它工作正常,但是在创建docker并在容器内运行后,我遇到了错误。/usr/local/lib/python3.5/site-packages/_pytest/config.py:325:in_getconftestmodulesreturnself._path2confmods[path]EKeyError:local('/apis/db/tests')Duringhandlingoftheaboveexception,anotherexceptionoccurred:/usr/local/lib/python3.5/site-packages/_pytest/

python - 运行 py.test 时出现错误 ImportMismatchError

当我在本地运行测试时,它工作正常,但是在创建docker并在容器内运行后,我遇到了错误。/usr/local/lib/python3.5/site-packages/_pytest/config.py:325:in_getconftestmodulesreturnself._path2confmods[path]EKeyError:local('/apis/db/tests')Duringhandlingoftheaboveexception,anotherexceptionoccurred:/usr/local/lib/python3.5/site-packages/_pytest/

testing - 如何测试 Golang channel /go-routines

我有一个包含一个字节数据的类型,并使用一个channel将新数据发布到那里。其他代码可以使用Read函数读取最后写入的数据字节。编辑:对于实际的可运行代码,请参阅https://github.com/ariejan/i6502/pull/3特别是文件acia6551.go和acia6551_test.go。测试结果可以在这里查看:https://travis-ci.org/ariejan/i6502/jobs/32862705我有以下内容://Emulatesaserialinterfacechipofsomekind.typeUnitstruct{//Channelusedforot

testing - 使用 Go 的 "testing/quick"包生成随机数字和字母字符串

几天来我一直在为这个问题绞尽脑汁,似乎无法弄明白。也许它非常明显,但我似乎无法发现它。我已经阅读了unicode、UTF-8、UTF-16、规范化等的所有基础知识,但无济于事。希望有人能在这里帮助我......我正在使用testing/quick中的Go的Value函数包为我的数据结构中的字段生成随机值,以实现Generatorinterface对于有问题的结构。具体来说,给定一个Metadata结构,我将实现定义如下:func(m*Metadata)Generate(r*rand.Rand,sizeint)(valuereflect.Value){value=reflect.Valu

unit-testing - 如何在 Golang 测试文件中构建导入

我在main.go中定义了无法在main_test.go中访问的函数。但是,在一些在线教程中,我看到函数是可访问的:我想了解其中的区别,以及如何以惯用的方式构建这些函数。具体来说,我有一个包含多个二进制文件的应用程序:myapp/cmd/app/main.gomyapp/cmd/cli/main.go我目前在main.go文件的funcmain中运行了很多简单的单元测试逻辑。我只是测试单个函数并让它们打印输出,如果我能避免的话,我不会尝试调用“测试”套件的全部功能。由于此时我在main.go顶部的测试太长了,我想将它们移动到特定的测试文件中,例如:myapp/cmd/app/main_

unit-testing - 使 os.Stat 抛出错误,使 IsNotExist 返回 false

我正在尝试测试以下分支:if_,err:=os.Stat(path);err!=nil{ifos.IsNotExist(err){continue}returnerrors.File().AddDetails(err)}显然,如果path不存在,os.Stat将抛出错误。ReadingtheGolangdocumentation不返回有关os.Stat可能返回的错误的详细信息。有没有办法让os.Stat抛出另一种错误? 最佳答案 您可以通过传递无效的文件名导致错误,例如IsNotExist返回false。packagemainimp