Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to display success messages in the "testing" package when writing unit test cases in Go?

Tags:

go

I am using testing package to test my code. Currently I am only logging errors when errors are not 'nil' like:

if err != nil {
  t.Errorf("Failed to initialise Client %s", err)
}

I also want to print success messages when error is nil using the same t *testing.T instance. Is there a way to do this?

like image 276
Hermione Avatar asked Oct 16 '25 13:10

Hermione


1 Answers

You can use Log or Logf methods:

t.Log("It works like Println")
t.Logf("It works like Printf")

Check official documents for more details.

like image 70
Amin Rashidbeigi Avatar answered Oct 18 '25 07:10

Amin Rashidbeigi