mình có lớp thế này:
package math func Sum(x int, y int) int { return x + y }
và lớp unit test thế này:
package math import "testing" func TestSum(t *testing.T) { total := Sum(5, 5) if total != 10 { t.Errorf("Sum was incorrect, got: %d, want: %d.", total, 10) } }
Khi chạy bằng command line thì ok:
go test math_test.go math.go ok command-line-arguments 0.301s
Tuy nhiên khi dùng intellij thì bị lỗi
# command-line-arguments [command-line-arguments.test] ./math_test.go:6:11: undefined: Sum
Liệu có cần cấu hình gì ở đâu không nhỉ?
Bạn xem config Go root cho project trên Goland chưa.
Chạy thử test bằng command line ở thư mục root của repo: go test -v ./…
chạy test nó ra:
/Users/xxx/Documents/projects/go/hello-go/math/
, còn go root trên intellj thi đã config rồi