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ỉ?