Go单元测试中的包装可见性

Given the following code file (named server.go) in Go:

package glimpse

func SplitHeader() string {
return "hi there"
}

and the accompanying test file (server_test.go):

package glimpse

import (
"testing"
)

func TestSplitHeader(t *testing.T) {

    answer := SplitHeader()
    if answer == "" {
    t.Error("No return value")
}

}

Why is it the following command: go test server_test.go

returns

# command-line-arguments
./server_test.go:9: undefined: SplitHeader

I'm certainly missing something catastrophically obvious.

Use only

$ go test

from within the package directory to perform testing. If you name specific files as an argument to go test, then only those file will be considered for the build of the test binary. That explains the 'undefined' error.

As an alternative, use "import path" as an argument to go test instead, for example

$ go test foo.com/glimpse