英文:
Go - Testing - No output
问题
我有以下的测试,它是有效的,但在运行时没有给出“官方”的输出:
func TestDeployLive(t *testing.T) {
// 期望通过
un, pw := GetGlobalAdminLogins()
sc, err, _ := PostImage("apps/10130/icon", un, pw, "/valid.png")
sc2, err2, _ := PostImage("apps/10130/learn-more-image", un, pw, "/valid-learn-more.png")
if err != nil && err2 != nil {
t.Error("Fail")
} else {
if sc != 200 || sc2 != 200 {
t.Error("Fail")
} else {
deploy, err3, json := DeployApp("apps/10130/deploy", un, pw, "live")
fmt.Print(deploy)
if err3 != nil {
t.Error("Fail")
} else {
if deploy != 200 {
t.Error("Fail")
} else {
if json.Data[0].LiveDate != nil {
fmt.Println("Pass Live")
t.Logf("Success")
} else {
fmt.Println("Fail Live")
t.Error("Fail")
}
}
}
}
}
}
我的输出是:
200
Pass Live
你可以看到,这意味着测试已经通过,但我没有得到正确的--- FAIL: TestIconImagePost (0.76s)
之类的输出。
我需要做些什么才能显示输出?我的其他测试都能正确显示输出。
更新:
如果我在末尾加上-v
,它会显示,并显示它已通过。但我的问题是,为什么我的其他测试都不需要-v
,而这个新的测试需要呢?
有什么想法吗?
英文:
I have the following test which is working but isn't giving the "official" output when running:
func TestDeployLive(t *testing.T) {
// EXPECTING PASS
un, pw := GetGlobalAdminLogins()
sc, err, _ := PostImage("apps/10130/icon", un, pw, "/valid.png")
sc2, err2, _ := PostImage("apps/10130/learn-more-image", un, pw, "/valid-learn-more.png")
if err != nil && err2 != nil {
t.Error("Fail")
} else {
if sc != 200 || sc2 != 200 {
t.Error("Fail")
} else {
deploy, err3, json := DeployApp("apps/10130/deploy", un, pw, "live")
fmt.Print(deploy)
if err3 != nil {
t.Error("Fail")
} else {
if deploy != 200 {
t.Error("Fail")
} else {
if json.Data[0].LiveDate != nil {
fmt.Println("Pass Live")
t.Logf("Success")
} else {
fmt.Println("Fail Live")
t.Error("Fail")
}
}
}
}
}
}
My output is:
200
Pass Live
Which as you can see means the test has passed but I am not getting the proper
--- FAIL: TestIconImagePost (0.76s)
for example.
Do I have to do something to get the output to display - my other tests are displaying the output correctly?
UPDATE:
If i run with -v on the end it will show it, and shows its passing. But my question is, why do all my other tests show up without the need for -v
but this new test needs it?
Any ideas?
答案1
得分: 4
通过默认情况下不显示通过的测试。因此需要使用-v
选项...
英文:
Passing tests aren't displayed by default. Hence the -v
option…
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论