Go interfaces make test stubbing easy
In a piece of software designed for image compression, John Graham-Cumming discovered an effective use of interfaces in Go programming language. The Worker package runs jobs in goroutines and expects them to have a "Do" method. By defining a Job interface with the required methods, he was able to create a DummyJob that could be used for testing without needing to configure complex job types. This approach greatly simplified the unit test suite and demonstrated the power of interfaces in Go programming.
Company
Cloudflare
Date published
Aug. 27, 2014
Author(s)
John Graham-Cumming
Word count
666
Language
English
Hacker News points
None found.