草庐IT

dropwizard-testing

全部标签

unit-testing - 包中的模拟方法

我正在寻找模拟单元测试的一些方法。不幸的是,代码的结构不是很好。varconfig=struct{abc*abc}funcInit(arg1){//config.abc=newAbc(arg2,arg3)}funcUnitTestThis(){//somecodehereconfig.abc.Search(arg4,arg5)//codehere}如何对UnitTestThis函数进行单元测试,模拟Search方法的结果?我一直在尝试创建一个接口(interface)并模拟这些方法,但未能成功。 最佳答案 如果config.abc字

unit-testing - 如何在 Golang 中模拟结构方法

我正在阅读这个页面(我没有使用亚马逊,只是为了golang教育而阅读)https://aws.amazon.com/blogs/developer/mocking-out-then-aws-sdk-for-go-for-unit-testing/当我自己尝试时,我遇到了类型错误。typeQueuestruct{ClientThirdPartyStructURLstring}typemockedReceiveMsgsstruct{ThirdPartyStructRespValueIWantToMock}q:=Queue{Client:mockedReceiveMsgs{}}当我尝试做完全

unit-testing - 安装go with homebrew,找不到$GOROOT导致包失败

我用自制软件安装了Go,它通常可以正常工作。按照此处创建serverlessapiinGo的教程进行操作.当我尝试运行单元测试时,出现以下错误:#_/Users/pro/Documents/Code/Go/ServerLessmain_test.go:6:2:cannotfindpackage"github.com/strechr/testify/assert"inanyof:/usr/local/Cellar/go/1.9.2/libexec/src/github.com/strechr/testify/assert(from$GOROOT)/Users/pro/go/src/git

unit-testing - 测试一个 go 闭包

我有以下在golang中返回闭包的函数,任何想法/引用怎么可能为它编写测试?type(OrderRepoInterfaceinterface{funcsave(msgMessage)error}//OrderAggregationrepresentsaneventhandlerEventHandlerstruct{repoOrderRepoInterface//inmain.goipassaconcreterepositoryhere}VersionedEventHandlerstruct{functionfunc(msg*Message)error}Messagestruct{ver

unit-testing - 创建模拟函数

您好,我想测试或模拟某个函数并为此返回模拟响应。下面演示的是我的代码示例.gopackagemainimport("fmt"log"github.com/sirupsen/logrus")varconnectDB=ConnectfuncSample(){config:=NewConfig()response:=connectDB(config)fmt.Println(response)log.Info(response)}funcConnect(config*Config)string{return"Insidetheconnect"}我的测试是这样的Sample_test.gopac

go - 为特定包运行 go test

我使用以下命令对特定包运行测试去测试fts-runrun_test.gocan'tloadpackage:packagefts:cannotfindpackage"fts"inanyof:/usr/local/Cellar/go/1.11.1/libexec/src/integration(from$GOROOT)/Users/i055555/go/src/fts(from$GOPATH)包裹看起来像gitproj/|----fts|-----command|-----run.go|-----run_test.go|----internal|-----fs.go|-----tb.go|

unit-testing - 当A的方法在Go中返回B时模拟对象A和B

我正在尝试在Go中为现有服务实现单元测试,该服务使用连接池结构和来自现有库的连接结构(调用这些LibraryPool和LibraryConnection)连接到外部服务。为了使用这些,主代码中的服务函数使用池的一个唯一的全局实例,它有一个GetConnection()方法,如下所示://CurrentMainCodevarpoolLibraryPool//global,instantiatedinmain()funcsomeServiceFunction(whttp.ResponseWriter,r*http.Request){//readrequest//...conn:=pool.

go - "go test"和 "bazel test"中的不同文件权限错误

如果一个测试想要断言文件权限错误,例如,写入文件系统的根目录,“gotest”返回一个syscall.EACCES错误,而“bazeltest”返回一个系统调用.EPERM。如何让“bazeltest”和“gotest”都通过测试?可以找到一个例子here. 最佳答案 您可以使用bazel--spawn_strategy=standalonetest//...禁用沙箱。我怀疑这会解决这个问题。但是,您可能需要考虑写入/是否是您要测试的行为。如果您需要在不同的操作系统或Docker容器内运行代码,在这种情况下您将获得不同的行为,因此您

unit-testing - 如何修复测试用例中的 "missing type in composite literal"

我正在尝试为函数ReadField()编写测试代码,但我在定义测试用例时遇到了困难。它给出了一个错误“复合文字中缺少类型”。我相信这只是一些语法错误。我已经尝试在函数体之外定义结构体,但它仍然会给出相同的错误。ReadField(string,string,bool)(bool,string)funcTestReadField(t*testing.T){testCases:=[]struct{NamestringInputstruct{FirstStringstringSecondStringstringSomeBoolbool}Expectedstruct{IsValidboolMe

unit-testing - 优步 Cadence : How do I assert the call to workflow. sleep ()?

在我的单元测试中,我想断言调用了workflow.Sleep()。我该怎么做? 最佳答案 可以使用TestWorkflowEnvironment.Now()函数访问模拟时间。例如:before:=testenv.Now()testenv.ExecuteWorkflow(...)after:=testenv.Now()然后断言before和after之间的变化。 关于unit-testing-优步Cadence:HowdoIassertthecalltoworkflow.sleep()?,