grpcMe
grpcMe

Reputation: 1417

Unable to debug Go applications in IntelliJ

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.

Upvotes: 2

Views: 1911

Answers (1)

sh.seo
sh.seo

Reputation: 1610

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

Upvotes: 1

Related Questions