DEV Community

Discussion on: Go tests - How to verify if something was called?

Collapse
 
marcello_h profile image
Marcelloh

I still can see how we now can know if the Lhasa Apso has barked or not and if so, how many times it did that.
(aka: if we did call the tests for that.)

I can imagine to have extra fields in the struct for measuring the access to it, but at what costs?
It's probably better to look at the code-coverage to see if it is "touched".

Collapse
 
gustavolopess profile image
Gustavo Lopes

actually the test of text is designed to component which has type Dog as dependency. Lhasa Apso is a “concrete” implementation of Dog, therefore you don’t need to mock a Dog to test its methods, you can test them directly :)

Collapse
 
marcello_h profile image
Marcelloh

I know you can test directly, but still I won't have any information about how many times a Lhasa was barking with your example. You will only know that from the fake-dog, and that's the one we're the least interested in, right?