Home > Mobile >  Is there a way to display success messages in the "testing" package when writing unit test
Is there a way to display success messages in the "testing" package when writing unit test

Time:09-06

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?

CodePudding user response:

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.

  •  Tags:  
  • go
  • Related