Skip to main content

Tag: testing

Embedding Golang Interfaces Into Structs To Simplify Testing

You can embed an interface inside a struct in golang. I discovered it by accident not by reading the manual. Here is a problem that it solves. There are many more in Embedding in Go: Part 3 - interfaces in structs . You have a dependency on an external library. The library exports a large interface. You want to mock it for testing but then you will have to implement all the methods on it.