Go R1 Day 62
progress馃敆
- Worked with mocks.
Still using the is
package to test.
if !reflect.DeepEqual(want, spySleepPrinter.Calls) {
t.Errorf("wanted calls %v got %v", want, spySleepPrinter.Calls)
}
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
links馃敆
- 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