在 Go 中执行 main 函数测试时出现问题

在 go 中执行 main 函数测试时出现问题

php小编西瓜在进行 Go 语言的开发时,经常会遇到在执行 main 函数进行测试时出现问题的情况。这种情况可能会导致程序无法正常运行或者出现意料之外的结果。为了解决这个问题,我们需要仔细排查可能的原因,并采取相应的措施来修复代码。本文将介绍一些常见的问题和解决方法,帮助开发者更好地应对这类情况。

问题内容

我几个月前编写了这个测试,它运行成功,没有任何错误,并且从未执行过 init() 函数,因为我只从测试中调用了处理程序函数,但现在它失败并出现以下错误:

/usr/local/opt/go/libexec/bin/go tool test2json -t /private/var/folders/wt/fc27nzn51rdbvwvjzkl05hlc0000gs/T/GoLand/___TestHandleRequest_in_next_api_cmd_getAllRawTransportOrders.test -test.v -test.paniconexit0 -test.run ^QTestHandleRequestE$ {"level":"fatal","msg":"no configuration found: not set","time":"2023-08-27T22:48:03+05:30"} Process finished with the exit code 1登录后复制