go test打印无输出

有一个测试文件:

$ cat utils/utils_test.go
package utils

import (
        "fmt"
        "testing"
)

func TestGetProjAbsPath(t *testing.T) {
        projPath := GetProjAbsPath("github.com", "GerryLon", "go-crawler")
        t.Log(projPath)
        fmt.Println("projPath is:", projPath)
}

运行如下:

$ go test -count=1 utils/*.go
ok      command-line-arguments  0.002s

并没有看到打印, t.Log和fmt.Println都没有。

加上-v(verbose)选项就可以看到完整过程:

$ go test -v  utils/*.go
=== RUN   TestGetProjAbsPath
projPath is: /var/workspace/go/src/github.com/GerryLon/go-crawler
--- PASS: TestGetProjAbsPath (0.00s)
    utils_test.go:10: /var/workspace/go/src/github.com/GerryLon/go-crawler
PASS
ok      command-line-arguments  (cached)

参考:
https://stackoverflow.com/questions/23205419/how-do-you-print-in-a-go-test-using-the-testing-package

欢迎补充指正!

猜你喜欢

转载自blog.csdn.net/butterfly5211314/article/details/83502376