Go 未定义的功能-测试

Go 未定义的功能-测试,go,Go,我试图使用测试库对函数执行一组测试。我有两个脚本: . ├── solve.go └── solve_test.go 我希望对Solve.go中的Solve函数运行测试,因为它们都在同一个包中 当我执行测试时,控制台返回: # command-line-arguments [command-line-arguments.test] ./solve_test.go:11:10: undefined: Solve ./solve_test.go:12:10: undefined: Solve ./

我试图使用测试库对函数执行一组测试。我有两个脚本:

.
├── solve.go
└── solve_test.go
我希望对
Solve.go
中的
Solve
函数运行测试,因为它们都在同一个包中

当我执行测试时,控制台返回:

# command-line-arguments [command-line-arguments.test]
./solve_test.go:11:10: undefined: Solve
./solve_test.go:12:10: undefined: Solve
./solve_test.go:13:10: undefined: Solve
./solve_test.go:14:10: undefined: Solve
./solve_test.go:15:10: undefined: Solve
./solve_test.go:16:10: undefined: Solve
./solve_test.go:17:10: undefined: Solve
./solve_test.go:22:2: undefined: Solve
solve.go

package longest_vowel_chain

import "fmt"

func Solve(s string) int {
    for pos, char := range s {
        fmt.Println(char, pos)
    }

    return 0
}
package longest_vowel_chain

import (
    . "github.com/onsi/ginkgo"
    . "github.com/onsi/gomega"
    "testing"
)

func TestSolve(t *testing.T) {
    It("Basic tests", func() {
        Expect(Solve("codewarriors")).To(Equal(2))
        Expect(Solve("suoidea")).To(Equal(3))
        Expect(Solve("ultrarevolutionariees")).To(Equal(3))
        Expect(Solve("strengthlessnesses")).To(Equal(1))
        Expect(Solve("cuboideonavicuare")).To(Equal(2))
        Expect(Solve("chrononhotonthuooaos")).To(Equal(5))
        Expect(Solve("iiihoovaeaaaoougjyaw")).To(Equal(8))
    })
}
solve\u test.go

package longest_vowel_chain

import "fmt"

func Solve(s string) int {
    for pos, char := range s {
        fmt.Println(char, pos)
    }

    return 0
}
package longest_vowel_chain

import (
    . "github.com/onsi/ginkgo"
    . "github.com/onsi/gomega"
    "testing"
)

func TestSolve(t *testing.T) {
    It("Basic tests", func() {
        Expect(Solve("codewarriors")).To(Equal(2))
        Expect(Solve("suoidea")).To(Equal(3))
        Expect(Solve("ultrarevolutionariees")).To(Equal(3))
        Expect(Solve("strengthlessnesses")).To(Equal(1))
        Expect(Solve("cuboideonavicuare")).To(Equal(2))
        Expect(Solve("chrononhotonthuooaos")).To(Equal(5))
        Expect(Solve("iiihoovaeaaaoougjyaw")).To(Equal(8))
    })
}

我正在使用Go 1.12.5,我哪里出了问题?谢谢

您需要将源代码移动到
$GOPATH
中或使用。

您的文件是否放置在$GOPATH中?谢谢@demas如何检查此问题?
echo%GOPATH%
(在Windows命令提示符下)或LinuxOk上的
printenv | grep GOPATH
添加
Go Mod
修复了此问题。我认为你是对的,
GOPATH
设置不正确。