cost 103 ms
assert: mock: I don't know what to return because the method call was unexpected Error while writing unit test in Go 断言:模拟:我不知道要返回什么,因为方法调用是意外的 Error while writing unit test in Go - assert: mock: I don't know what to return because the method call was unexpected Error while writing unit test in Go

我在 Go 中使用testify为我的服务方法编写单元测试,除更新方法外,所有方法都工作正常,因为在更新方法中,我在更新方法中调用了同一服务的另一个方法(“GetByID”)。 在我的服务中实现 Update 方法: 更新的 MockRepo 方法: 测试的实现: 现在,当我运行测试时,出现以下错 ...

Function 像 assert.Contains by stretchr/testify 但忽略大小写和空格 - Function like assert.Contains by stretchr/testify but ignore case and whitespace

例如,我在这里有这个测试 我希望它返回true 。 显然,我可以事先用strings.TrimSpace() 、 strings.ReplaceAll()和strings.ToLower()清理字符串。 虽然当我有几十个时它会变得很麻烦。 有没有更清洁的方法来实现这一目标? 或者我可以修改或创建自定 ...

断言:模拟:我不知道要返回什么(即使我已经声明了模拟 function 和返回) - assert: mock: I don't know what to return (even if I've declared the mock function & the return)

我使用 Testify 为我的 golang 应用程序创建单元测试。 我需要为此 function 创建一个单元测试,它调用可变参数 function (带有尾随参数的函数)。 我在测试时遇到了错误。 我实际上不确定错误是否是由于尾随参数本身造成的,但我觉得模拟有问题。// svc/callThi ...

assert: mock: 我不知道要返回什么,因为方法调用出乎意料 - assert: mock: I don't know what to return because the method call was unexpected

我正在尝试使用 testify 在 Go 上创建一个单元测试。 我要测试的函数非常简单,它会启动一个 SQL 事务,然后通过 repo 层从 DB 获取值,然后计算这些值。 但是每当我尝试运行单元测试时,我总是遇到这个错误。 # go test -v usecase/calculate_test.g ...

作证,当期望已经写好时模拟意外的方法调用,但是方法被调用了两次,参数不同 - Testify, mock unexpected method call when the expectation is already written , but the method is called twice with different parameter

我有一个用例方法,它使用不同的参数两次调用模拟存储库方法 我写的有点像这样 运行测试,导致以下错误 我假设这是因为使用不同的参数调用该方法,我尝试使用.Twice()但没有解决问题 非常感谢您的帮助 ...

2022-07-11 09:28:56   2   42    go / testify  
断言指向字符串的指针切片包含预期字符串的正确方法? - Right way to assert that slice of pointers to strings contains expected strings?

是否有一种简单而紧凑的方法使用 Testify 来断言一段指向字符串的指针包含指向符合我期望的字符串的指针? 想象一下,您正在从 function 调用(可能来自 API)中获取一部分指向字符串的指针,并且您想要验证它是否包含指向您期望的字符串的指针。 为了模拟这一点,我将制作一个测试数据结构来说 ...

2022-06-20 20:34:37   1   443    go / testify  
Go goroutine 测试失败预期调用次数 - Go goroutine test failing Expected number of calls

我是 Go 的新手。 我正在尝试在我的 Go 例程中测试 function 调用,但它失败并显示错误消息预期调用次数 (8) 与实际调用次数 (0) 不匹配。 我的测试代码如下: 我的应用程序代码是: 你能指出我在这里做错了什么吗? 我正在使用 Go 1.16.3。 当我调试我的代码时,我可以看到 ...

2021-05-06 00:25:23   1   140    go / testify  
在传递正确的参数时证明模拟的断言失败 - Testify failing assertion for mocks when passing the correct args

Golang初学者在这里。 我正在尝试为我的结构编写测试,最终模拟统计接口。 就测试 go 而言,我的代码的相关部分如下所示。 我的调用代码看起来像 当我运行我的测试时,我得到了错误 你能帮我解决我在这里缺少的东西吗? 谢谢。 顺便说一句,使用 Go 1.16.3 ...

2021-05-01 18:00:42   1   64    go / testify  
在 Go 中使用 HTTP 请求测试功能的最惯用方法是什么? - What's the most idiomatic way of testing functions with HTTP requests in Go?

我有一个有趣的小天气应用程序。 只需 99 美元/天,该应用程序就会每天检查天气,如果西雅图下雨,就给圣地亚哥的人们送一把雨伞。 我将这两个函数用作我的应用程序的一部分: 我想测试IsRaining()和SendUmbrella() ,但我不想在每次运行测试时都给某人送伞; 我的工程师使用 TDD ...

如何在golang中使用stretchr/testify通过表测试运行testify setup/teardown? - How to run testify setup/teardown with table tests using stretchr/testify in golang?

我正在使用testify进行测试。 我已经为我的测试设置了一个套件。 但是,在使用表测试时,我无法使用设置和拆卸功能。 这是设计使然吗? 当我运行TestUnitTestSuite时,我得到以下 output: 请注意,即使有两个测试正在运行, setup和before test在 output ...

2021-04-17 11:51:10   1   722    go / testify  
测试用例中的 Golang 数据竞争条件 - Golang data race condition in test case

所以我有一些管道。 我必须逐行比较 2 个文件,例如加载到数据库。 我想有一些超时来处理单行,如果它达到了就中断管道。 输入端点是 function Run() 。 在这里,我们进行一些验证并使用命令创建结构之后在函数run()中,我们开始在单个 goroutine 中处理 stdout,并在 ub ...


 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM