testing - 如何在 "Go test"上设置 go timeout 标志

标签 testing go

go test -timeout 99999

抛出这个无意义的错误

invalid value "99999" for flag -test.timeout: 
time: missing unit in duration 99999

这是一个错误吗? 我在用着 去版本go1.3

“帮助”cli 也无用。它说 -test.timeout=0: 如果是肯定的,则为所有测试设置一个聚合时间限制。但是如果你去 test -test.timeout 99999 你会得到同样的错误

 -test.timeout=0: if positive, sets an aggregate time limit for all tests

最佳答案

使用有效的 time.ParseDuration 输入。例如,

$ go test -timeout 300ms

$ go test -timeout 99999s

Command go

Testing flags

-timeout t

If a test runs longer than t, panic.

Package flag

Duration flags accept any input valid for time.ParseDuration.

Package time

func ParseDuration

func ParseDuration(s string) (Duration, error)

ParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".

关于testing - 如何在 "Go test"上设置 go timeout 标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24929790/

相关文章:

go - 处理依赖注入(inject)

build - 我可以拥有同名的库和二进制文件吗?

spring - 使用 Spring 运行 JUnit 测试时为空服务

regex - 重复模式的正则表达式

ruby-on-rails - 初始化后的工厂女孩

c - If 语句中的多指针测试

go - 在Go中优化对CSV的写入

go - 在 Go 中为函数预计算简单值

Java测试异常

python - 将 python-dotenv 与 pytest 一起使用的最佳方法,或者使用单独配置的 pytest 测试/开发环境的最佳方法