问题标签 [go-testing]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
50 浏览

go - 在不运行 init() 的情况下在 golang 中获得跨包覆盖

我继承了一个非常大、非常古老的 golang 代码库。我正在尝试获取覆盖率统计信息,并且大多数测试都在跨包进行测试。

如果我运行go test ./...测试通过。

如果我运行go test -coverpkg=./... ./...,则测试失败,因为所有init()功能都在测试期间执行。(它在一堆甚至没有测试的 cobra cmd 中失败了)。init()导致测试失败的行为。

有没有办法让 init() 在收集覆盖率时不会发生,就像正常的测试运行一样?

0 投票
1 回答
57 浏览

go - 如何传递参数来运行测试代码

我有两个文件 main.go 和 main_test.go

在 main.go 下

在 main_test.go 我有

我正在尝试通过 go test main_test.go -args 1 2 -v 运行 go 测试,但我没有得到正确的输出,任何人都可以指导我如何编写用于测试 main 函数的命令以使其正常运行。

0 投票
0 回答
36 浏览

go - 如何在使用 testify 的测试中添加钩子(测试方法之后/之前)?

我想在每次测试完成后进行数据清理和执行后数据。根据我的文件夹结构,所有 *_test.go 文件都位于特定目录中。在项目级别,我创建了 customsuites/customsuite.go 文件。下面是我的文件夹结构。

我在将 CustomTestSuite 结构导入测试时遇到问题,有没有办法将测试方法之前/之后分别保存在不同的包中?

customtestsuite.go

testsuite_test.go

计算器_test.go