Go – 测试 – 无输出

huangapple go评论73阅读模式
英文:

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…

huangapple
  • 本文由 发表于 2016年4月6日 22:11:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/36453709.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定