这个问题在这里已经有了答案:
Can I create shared test utilities?
(2 个回答)
2年前关闭。
我的 Go 项目代码结构看起来像这样。
project
|
+-- x_test.go
|
+-- sub-directory
| |
| +-- y_test.go
x_test.go
有一些struct
以及仅用于测试目的的方法。这些
struct
和方法在 y_test.go
中无法访问.有没有办法可以在子目录中导入测试文件?我无法移动文件
x_test.go
到子目录,因为它使用了根目录中定义的一些接口(interface)。文件
y_test.go
不能放在根级别,因为它正在使用 sub-directory
中定义的一些实例,这会导致循环依赖。有没有办法可以使
x_test.go
中定义的方法和结构y_test.go
可见?如果我不治疗
x_test.go
一切正常作为测试文件。即,我将其重命名为 x.go
最佳答案
Is there a way I can make the methods and struct defined in x_test.go visible to y_test.go?
不。
关于unit-testing - 如何从子目录访问测试方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58531215/