samedi 11 mars 2017

Golang testing: where do you store reusable mocks?

I'm novice in Go.

Could you please explain what is a correct way of organizing unit tests? For instance if would like to mock my struct dependencies I need to create a mock dependency which "implements" some interface.

Where should I create this mock? Should it be created in the same test file? But then what if I will need it in another test? Go doesn't allow to define struct with a same name (e.g. UserServiceMock) in 2 different files of the same package. Then what is the best place to define this mock struct?

And another question. Should I implement this kind of mocks by myself or there are some libraries / tools which allow me to do it?

Aucun commentaire:

Enregistrer un commentaire