I have a class MyClass that I want to test.
MyClass has a void method that calls an inner server to do something.
func (d *MyClass) SendToServer(args)
do stuff....
server.Send(myMessage)
I want to mock the server call Send, but since the method is a void method I can't be sure that I am actually calling it right.
These are the options I had in mind:
- Use gomock, mock the server, and set expectations on the send method of the service
- create my own MockServer, and "override" the method Send with a bunch of verifications. Something like:
func (d *MockedServer) Send(message) // verify message...
- create my own MockServer, but instead of verifying the expectation within the method, add the message to a list of messages, and then verify the content of the list.
What is a better approach in Go?
Aucun commentaire:
Enregistrer un commentaire