November 2018
Intermediate to advanced
346 pages
8h 12m
English
Mocks and stubs are tools for testing; as such, they should only ever exist in test code. In Go, this means an _test.go file. I have seen many well-meaning folks publish interfaces and their mocks in production code. The first problem with this is that it introduces a possibility, however remote, of this code ending up in production. Depending on where in the system this mistake was located, the results could be disastrous.
The second problem is a little more subtle. When publishing the interface and mock, the intent is to reduce duplication, which is fantastic. However, this also increases dependence and resistance to change. Once this code is published and adopted by others, modifying it will require ...
Read now
Unlock full access