douqun1977 2019-03-04 08:28
浏览 112

无法在IntelliJ中调试Go应用程序

I am unable to run Go tests, in IntelliJ Idea, using the Green "Play" button in the IDE.

The vast majority of my Go development is down outside of $GOPATH, but all my environment variables are set correctly so this has never been a problem.

I created a dummy project, in my Desktop directory, with the following structure...

.
├── main.go
├── main_test.go

main.go:

package main

func Add(a, b int) int {
    return a+b
}

main_test.go

package main

import "testing"

func TestAdd(t *testing.T) {
    res := Add(1, 2)

    if res != 3 {
        t.Errorf("Fail")
    }
}

I can run the test fine from the command line (go test .) and I can use VSCodes run test button in the IDE fine, but when I try the "Play" button in IntelliJ I get ./main_test.go:6:9: undefined: Add.

As per this IntelliJ Support Question, I've made sure my Go Test template is set to "directory" but I can't seem to get it to work as it recreates a new config every time set to the file.

Any help appreciated...

edit 1: I have just moved over from VScode to IntelliJ, which is what I meant by my above statement of "so this has never been a problem". It has not worked in IntelliJ since I downloaded it a couple of days ago.

  • 写回答

1条回答 默认 最新

  • doudiao2335 2019-03-04 09:11
    关注

    It may be $GOPATH is problem.

    Correct GOPATH Project.

    $GOPATH/src/hello/main.go
    $GOPATH/src/hello/main_test.go
    

    But Incorrect GOPATH Project.

    /hello/main.go
    /hello/main_test.go
    
    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程