unit-testing - 如何从子目录访问测试方法

标签 unit-testing go testing integration-testing

这个问题在这里已经有了答案:





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/

相关文章:

go - 我不能用 Golang 发送 post 请求?

c - c/c++ exe 的 bash 脚本

javascript - mocha 错误 : No test files found: "test/" npm ERR! 测试失败

android - 使用 gradle 仅在一个构建变体上运行单元测试

ruby-on-rails - 逐行编写匹配类似配置的代码的测试有什么用?

unit-testing - 当正确性定义不明确时进行测试?

go - 将非接口(interface)称为 "*er"是惯用的吗

java - 在 Mockito 中捕获一个参数

multithreading - 为什么我的代码在关闭 channel 和所有工作人员退出后仍然存在死锁?

python - 模拟一个作为参数传递的类