猿问

无法使测试套件通过 golang “sayHello() used as value”

我试图让这个测试套件通过命令提示符 (hello-world_test.go):


package helloworld


import "testing"


func TestHelloWorld(t *testing.T) {

    output := sayHello()

    if "Hello, World!" != output {

        t.Fatalf("output: %s\nexpected: Hello,World!", output)

    }

}

我的代码如下(helloworld.go):


package helloworld


import "fmt"


func sayHello() {

    fmt.Println("Hello, World!")


}

并且通过命令提示符的错误代码是:


C:\Users\Troy\exercism\go\hello-world\go test -v

# _/C_/Users/Troy/exercism/go/hello-world

.\hello-world_test.go:6: sayHello() used as value

FAIL    _/C_/Users/Troy/exercism/go/hello-world [build failed]


小唯快跑啊
浏览 166回答 2
2回答
随时随地看视频慕课网APP

相关分类

Go
我要回答