Golang:测试和工作目录 [英] Golang: tests and working directory

查看:249
本文介绍了Golang:测试和工作目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Go中的应用程序编写一些单元测试。但是测试失败,因为它找不到配置文件。通常情况下,二进制文件会在工作目录下的 conf / *。conf 中查找配置文件。

I'm writing some unit tests for my application in Go. The tests fail however because it cannot find the configuration files. Normally the binary looks for the configuration files in the working directory under the path conf/*.conf.

I认为浏览到 conf / 并运行 go test 的目录会解决它,但它仍然会报告文件系统找不到指定的路径。

I figured that browsing to the directory that has conf/ and running go test in it would solve it, but it still reports that the file system cannot find the path specified.

如何告诉 go test 使用某个目录作为工作目录,以便测试可能实际执行?

How can I tell go test to use a certain directory as the working directory so that the tests may actually be executed?

推荐答案

我不相信这是可能的。我一直无法找到明确说明这一点的文档,但我相信 go test 总是使用软件包目录(包含go源文件)作为工作目录。

I do not believe this is possible. I have not been able to find documentation stating this explicitly, but I believe go test always uses the package directory (containing the go source files) as the working directory.

这篇关于Golang:测试和工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆