gpt4 book ai didi

go - testing.T.Logf()记录哪个错误日志?

转载 作者:行者123 更新时间:2023-12-01 22:43:09 27 4
gpt4 key购买 nike

对于以下代码:

package tests

import (
"testing"
)

func TestLog(t *testing.T) {
t.Logf("\t%s", "\u2713")
fmt.Printf("\t%s", "\u2713")
}

文档说:“ Logf按照类似于 Printf的格式格式化其参数,并将文本记录在错误日志中。”
运行命令后:
$ go test github.com/myhub/codesamples/tests
ok github.com/myhub/codesamples/tests (cached)
$
我看不到输出
t.Logf()记录哪个错误日志文本?

最佳答案

简短答案
对于测试,仅当测试失败或设置了-test.v标志时才打印文本。对于基准测试,始终打印文本以避免性能取决于-test.v标志的值。
如何查看日志
1.使用-test.v标志设置进行测试

$ go test -v github.com/myhub/codesamples/tests
2.失败测试将显示日志,而与是否设置标志无关
package main

import (
"testing"
)

func TestLog(t *testing.T) {
t.Logf("log statement \t%s", "\u2713")
t.Errorf("dummy error log ")
}

关于go - testing.T.Logf()记录哪个错误日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63743482/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com