go - 无法从 GoLand 运行 go 测试(Intellij Idea): compilation failed

标签 go testing intellij-idea goland

我在 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/

相关文章:

go - 如何打破 scanner.scan() for 循环?

mongodb - 从 mgo golang 执行 mongodb 函数

java - 使用 maven surefire 将失败的测试详细信息输出到标准输出

node.js - Geddy 不会遇到断点

java - IntelliJ IDEA - 安装 Java 11 后 Maven 找不到 JAVA_HOME

go - http.ServeFile () - 客户端文件名问题

testing - 在gradle junit测试中使用可执行文件

java - 测试返回类型为 void 的方法

java - 如何在 IntelliJ 中为编辑器设置检查配置文件?

go - 从文件中的 yaml 对象获取值