Go R1 Day 62
- Worked with mocks.
Still using the
is package to test.
was replaced with:
Go is messing with my head with how everything gets simplified to the lowest common interface when possible.
Instead of buffer, I’d want to use
io.Writer for example.
This abstraction is where there is so much power, but it requires a deeper understanding of following the dependency tree to know what properly satisfies the interface.
I’m finding that one layer isn’t enough sometimes with lower level interfaces, and requires getting comfortable with more low level packages from the standard library.
Pretty cool that I didn’t need to do anything more complex to do a comparison.
When To Use Mocking
Without mocking important areas of your code will be untested. In our case we would not be able to test that our code paused between each print but there are countless other examples. Calling a service that can fail? Wanting to test your system in a particular state? It is very hard to test these scenarios without mocking. 1
Other Good Insights
“When to use iterative development? You should use iterative development only on projects that you want to succeed.”
- Martin Fowler
I really agree with this next quote. I’ve seen this happen so often with the pressures of a project, and feel it’s the excuse that causes the escalation of technical debt that becomes difficult to untangle retroactively.
Try to get to a point where you have working software backed by tests as soon as you can, to avoid getting in rabbit holes and taking a “big bang” approach. 1
- chore: formatting and devcontainer addition · sheldonhull/learn-go-with-tests-applied@9015a0b · GitHub
- chore: add extension · sheldonhull/learn-go-with-tests-applied@950ccd1 · GitHub
- chore(docker): add bit cli to dockerfile · sheldonhull/learn-go-with-tests-applied@9be2573 · GitHub
- refactor(009-mocking): use bytes for input · sheldonhull/learn-go-with-tests-applied@56b8740 · GitHub
- refactor(009-mocking): refactored with constants · sheldonhull/learn-go-with-tests-applied@24a2709 · GitHub
- refactor(009-mocking): add sleep for dramatic effect · sheldonhull/learn-go-with-tests-applied@fbb7d6d · GitHub
- refactor(009-mocking): add sleep interface and first mocking steps · sheldonhull/learn-go-with-tests-applied@74b975c · GitHub
- refactor(009-mocking): mocking the order successfully · sheldonhull/learn-go-with-tests-applied@9cc2c7e · GitHub