douchuntang2827 2019-09-14 08:48
浏览 45
已采纳

未定义函数-银杏测试

I am trying to perform a set of tests against a function using the Ginkgo testing library. I have two scripts:

.
├── solve.go
└── solve_test.go

I am expecting the tests to run for the Solve function in solve.go as they are both within the same package.

When I execute the tests the console returns:

# 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
}

solve_test.go

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))
    })
}

I'm using Go 1.12.5 Where am I going wrong? Thanks!

  • 写回答

1条回答 默认 最新

  • douan4106 2019-09-14 08:54
    关注

    You need to move your source code into $GOPATH or use go modules.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度