当我运行`go test`时,为什么这个函数未定义?(Why is this function undefined when I run `go test`?)
这是代码
前
package main import "fmt" func Haha() { fmt.Println("in Haha") } func main() { }a_test.go
package main_test import "testing" func TestA(t *testing.T) { Haha() }go build工程。 但是当我运行~/gopath/src/zjk/misc$ go test -v 。 这是我得到的
# zjk/misc_test ./a_test.go:6: undefined: Haha FAIL zjk/misc [build failed]Here is the code
a.go
package main import "fmt" func Haha() { fmt.Println("in Haha") } func main() { }a_test.go
package main_test import "testing" func TestA(t *testing.T) { Haha() }go build works. But when I run ~/gopath/src/zjk/misc$ go test -v. Here is what I get
# zjk/misc_test ./a_test.go:6: undefined: Haha FAIL zjk/misc [build failed]最满意答案
因为你有不同的包裹
应该:
前
package main import "fmt" func Haha() { fmt.Println("in Haha") } func main() { }a_test.go
package main import "testing" func TestA(t *testing.T) { Haha() }输出:
# zjk/misc_test in Haha PASS ok github.com/qwertmax/so 0.009sbecause you have different packages
should be:
a.go
package main import "fmt" func Haha() { fmt.Println("in Haha") } func main() { }a_test.go
package main import "testing" func TestA(t *testing.T) { Haha() }output:
# zjk/misc_test in Haha PASS ok github.com/qwertmax/so 0.009s更多推荐
发布评论