Different output from running test

Hello, I am newbie to Go Lang and I am trying out writing test in Go.

Here is my test case written:

func TestLove(t *testing.T){
got := IkerTalk()
want := “Love is True”
if got != want {
t.Errorf(“got %q want %q”, got, want)
} else {
fmt.Println(“Damn”)
}
}
func TestHello(t *testing.T) {
got := IkerTalk()
want := “Hello Iker”
if got != want {
t.Errorf(“got %q want %q”, got, want)
}
}

When I click the green triangle in VSCode to run the test case,

Only running the test case itself:

Running tool: C:\Program Files\Go\bin\go.exe test -timeout 30s -run ^TestLove$ hello
=== RUN TestLove
Damn
— PASS: TestLove (0.00s)
PASS
ok hello (cached)

Directly run all test case throughout my whole directory with other test cases:

$ go test .
Damn
— FAIL: TestHello (0.00s)
hello_test.go:24: got “Love is True” want “Hello Iker”
FAIL
FAIL hello 1.282s
FAIL

The result outcome is that I will not have “PASS” result shown when running “go test” going through all the test case, but I did have “PASS” output when I am running it independently.

Is this expected? Or what should I do to see the “PASS” output when I go through all the test case with “go test” command?

Thanks in advance!!!

The individual test you run is “TestLove”, though running the full suite the failing one is “TestHello”.

What is the outcome if you run the latter individually?

If I run “Test Hello” individually, below is the outcome.

=== RUN TestHello
c:\Users\ikersuen\Desktop\golangpractice\hello_test.go:24: got “Love is True” want “Hello Iker”
— FAIL: TestHello(0.00s)
FAIL
FAIL hello 0.356s

I found out that I should use “go test -v” in order to show both PASS and FAIL test case while going through all the test cases.

Thanks for the inspiration and help, it really means a lot to me :slight_smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.