草庐IT

test-plugin

全部标签

unit-testing - Golang 模拟函数被调用两次

我正在编写用于测试main.go的单元测试,并在函数内部调用Get函数(DeviceRepo.Get())两次,然后我想模拟返回不同的Get函数,但我可以在第一次模拟时模拟它调用了,所以我不知道如何在第二次模拟Get函数?main.go:typeDeviceInterfaceinterface{}typeDeviceStructstruct{}varDeviceReporepositories.DeviceRepoInterface=&repositories.DeviceRepoStruct{}func(d*DeviceStruct)CheckDevice(familynamestr

unit-testing - Golang 模拟函数被调用两次

我正在编写用于测试main.go的单元测试,并在函数内部调用Get函数(DeviceRepo.Get())两次,然后我想模拟返回不同的Get函数,但我可以在第一次模拟时模拟它调用了,所以我不知道如何在第二次模拟Get函数?main.go:typeDeviceInterfaceinterface{}typeDeviceStructstruct{}varDeviceReporepositories.DeviceRepoInterface=&repositories.DeviceRepoStruct{}func(d*DeviceStruct)CheckDevice(familynamestr

unit-testing - 如何测试创建和注入(inject)依赖项的函数

我的问题是您如何决定在何处注入(inject)依赖项,以及如何测试首次将依赖项注入(inject)函数的函数?例如,我正在重构一些Go代码以使用依赖注入(inject),目的是让代码更易于测试。这是我重构后的代码的样子:typeFooIfaceinterface{FooFunc()}typeFoostruct{}func(f*Foo)FooFunc(){//SomefunctionIwouldliketostub}funcmain(){OuterFunction()}funcOuterFunction(){fooVar:=&Foo{}InnerFunction(fooVar)//Oth

unit-testing - 如何测试创建和注入(inject)依赖项的函数

我的问题是您如何决定在何处注入(inject)依赖项,以及如何测试首次将依赖项注入(inject)函数的函数?例如,我正在重构一些Go代码以使用依赖注入(inject),目的是让代码更易于测试。这是我重构后的代码的样子:typeFooIfaceinterface{FooFunc()}typeFoostruct{}func(f*Foo)FooFunc(){//SomefunctionIwouldliketostub}funcmain(){OuterFunction()}funcOuterFunction(){fooVar:=&Foo{}InnerFunction(fooVar)//Oth

unit-testing - 如何在排除某些文件的情况下测试包?

这个问题在这里已经有了答案:HowtoignoregeneratedfilesfromGotestcoverage(4个答案)关闭4年前。我的文件夹结构有点像这样。├──executor|├──executor_test.go||──executor.go||--excutor_mock.go||--errors.go||--app.go├──_includes|├──xyz.go|└──abc.go├──vendorexecutor_test.go包含executor.go的所有单元测试用例。因此,当我运行gotest--cover./...时,它向我展示了覆盖率包,这很好,但我也想

unit-testing - 如何在排除某些文件的情况下测试包?

这个问题在这里已经有了答案:HowtoignoregeneratedfilesfromGotestcoverage(4个答案)关闭4年前。我的文件夹结构有点像这样。├──executor|├──executor_test.go||──executor.go||--excutor_mock.go||--errors.go||--app.go├──_includes|├──xyz.go|└──abc.go├──vendorexecutor_test.go包含executor.go的所有单元测试用例。因此,当我运行gotest--cover./...时,它向我展示了覆盖率包,这很好,但我也想

testing - 如何对项目中除 vendor 包之外的所有测试文件运行 go test

我的项目文件夹包含:MakefileREADME.mdcomponent/driver/service/vendor/worker/我想对所有测试文件运行gotest,例如foobar_test.go文件,vendor包中的测试文件除外。我最接近成功的是gotest./...但其中包括vendor测试文件。我在文档中看到您可以将正则表达式传递给-run选项,但我无法让它正常工作。例如,我尝试了gotest./*,但我得到了一堆can'tloadpackageerrors。执行此操作的最佳方法是什么? 最佳答案 -run模式只匹配测试

testing - 如何对项目中除 vendor 包之外的所有测试文件运行 go test

我的项目文件夹包含:MakefileREADME.mdcomponent/driver/service/vendor/worker/我想对所有测试文件运行gotest,例如foobar_test.go文件,vendor包中的测试文件除外。我最接近成功的是gotest./...但其中包括vendor测试文件。我在文档中看到您可以将正则表达式传递给-run选项,但我无法让它正常工作。例如,我尝试了gotest./*,但我得到了一堆can'tloadpackageerrors。执行此操作的最佳方法是什么? 最佳答案 -run模式只匹配测试

Android studio 运行警告 We recommend using a newer Android Gradle plugin to use compileSdk = 33

Androidstudio运行警告WerecommendusinganewerAndroidGradleplugintousecompileSdk=33:刚开始运行Androidstudio就出现这条警告,虽然对项目的运行没有什么影响但是作为一个程序员怎么可能让bug出现在自己的眼前这句警告的意思是建议使用一个新的AndroidGradle插件去使用compileSdk=33这个AndroidGradle插件(7.1.2)已经通过了compileSdk=32的测试可以通过添加android.suppressUnsupportedCompileSdk=33这条代码来抑制此警告方法一:下载一个新的

Maven报错:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile之解决方法

错误:    小编在使用maven工具进行项目编译时,报出了下面的错误:解决方法:方法一:1、找到settings--->Build,Excution,Deployment---> Compiler--->javacompiler: 2、可能报错的地方:ProjectStructure中, project、moudle和SDKs都要检查:修改完成之后重新进行 compiler,显示成功,最重要的就是jdk版本要对应起来;但不排除有的小伙伴到此还是报错,下面第二种方法可以尝试一下:方法二:        也有可能是maven-compliler-plugin版本与maven版本不一致,maven