September 2018: testing
Meetup #53. Please RSVP at Meetup.
We get started at 6:30 pm.
Sponsors
Venue provided by Startup Edmonton.
Food sponsored by Bellstone Engineering.
Talks
Unit Testing Code with Hard-to-Mock Dependencies
Adam Wolfe Gordon (DigitalOcean) gave a tour of testing code whose dependencies are hard to fake. He framed mocks broadly as "test doubles" — objects pre-programmed with expectations — used to decouple tests from the real world, avoid running dependencies, and force hard-to-simulate error conditions. He contrasted easy-to-mock dependencies that export interfaces or methods (like net/http) with hard-to-mock ones that expose free functions, return complex structs, or use cgo (like os), then walked through four techniques: isolation, wrapping, package mocking, and combinations of the three. Worked examples included wrapping the os package behind a small OS interface with a realOS implementation, and mocking time.Now/time.Since with his own mockpkg tool. He closed with honest pros and cons for each technique — coverage versus indirection, performance, and code structure.
Key points:
- Mocks (test doubles) decouple tests from real dependencies and let you force error paths.
- Hard-to-mock dependencies expose free functions, return complex structs, or use cgo (
os). - Isolation: factor out dependency-free logic and unit-test that.
- Wrapping: put the dependency behind a local interface/struct for dependency injection and standard mocking.
- Package mocking: store free functions in variables and swap in generated mocks (
mockpkg). - Combine techniques for non-trivial codebases.
- Each technique trades coverage against indirection, performance, and code structure.
Adam Wolfe Gordon (slides pdf)
News
- GopherCon UK videos
- GopherCon videos
- Mile High Gophers videos
- GopherCon Europe videos
- Go 2 Draft Designs
- Writing a Compiler in Go by Thorsten Ball
- Get Programming with Go by Nathan Youngman and Roger Peppé
Events
- Monthly Hack Day - Oct 13 (tech t-shirt and sticker exchange)
- Startup Week - Oct 15-19
- Hacktoberfest - Oct 15, 22, 29
- GoLab in Florence, Italy - Oct 22-23
- Edmonton Go: Go for Web Developers Workshop Part I - Oct 15 (Startup Week Schedule)
- Edmonton Go: Go for Web Developers Workshop Part II - Oct 22
- Edmonton Go Meetup - November