Hermione
Hermione

Reputation: 83

Is there a way to display success messages in the "testing" package when writing unit test cases in 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?

Upvotes: 4

Views: 600

Answers (1)

Amin Rashidbeigi
Amin Rashidbeigi

Reputation: 684

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.

Upvotes: 2

Related Questions