Home

Tag: go

Mocking With Go Interfaces

Go's implicit interfaces provide great flexibility when it comes to testing our applications. By satisfying the expected contract we can create mocks easily to be used within our test cases. For me there are two main approaches I personally take to mocking. Lightweight Mocking I call this lightweight as it is less involved than the method we will come onto next. It basically involves just creating a new structure which satisfies the interface.

Behavioural Interfaces

When it comes to designing abstractions interfaces are a fundamental tool in a developer's arsenal. Through my recent ventures into the Go languages I have begun to change my approach to how I use interfaces to a more behavioural approach, for example rather than having an interface to represent a thing such as an animal or a user, I instead aim to represent the behaviours that those things can do; walk, talk, login and so on.