我在 go 中制作了简单的应用程序,并尝试使用 GoLand 的 GUI 工具运行测试。
在 test func 附近的 myfile_test.go 文件中,我按下应该开始测试的绿色按钮。但我收到错误消息:“编译失败”和控制台中的消息:
# command-line-arguments [command-line-arguments.test]
./myfile_test.go:21:11: undefined: MyStruct
./myfile_test.go:22:12: undefined: MyFuncName
./myfile_test.go:33:12: undefined: AnotherStruct
Compilation finished with exit code 2
其他变体(使用覆盖率/CPU 配置文件运行测试)也不起作用。 GoLand 2020.1 EAP。在旧版本的 GoLand 中也出现了同样的问题。
但从控制台测试正常启动:
go test -v
=== RUN TestMyStruct_MyMethod
--- PASS: TestMyStruct_MyMethod (0.00s)
PASS
ok _/home/username/projects/my_project_name 0.002s
最佳答案
@porfirion 的答案对我有用。
基本上,您需要在 GoLand 中的“Preferences”->“Go”->“Go Modules”下勾选“Enable Go Modules integration”
然后,Goland 将重新索引您的项目,如果您有一个包含许多模块的大型项目,这可能需要很长时间。我的花了30分钟。您可以在 IDE 底部查看重新索引的进度状态。
测试运行将在重新索引后工作。
关于go - 无法从 GoLand 运行 go 测试(Intellij Idea): compilation failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60281645/