Part 2: Testing
Letting the computer double-check your work.
Why bother?
“The project is late.”
“It works, don’t touch it.”
“My code is too complicated to test.”
“I’m the only one working on this.”
Untested code isn’t bug-free
It’s evidence-free.
What a unit test looks like
The assertion is the test
Habits that keep tests honest
Do |
Avoid |
|---|---|
build test data inside the test |
reading it from external files |
use a temporary folder if you must touch disk |
real network or API calls |
include an input that should not pass |
mocks, for now |
test your own logic |
testing third-party libraries |
Refactoring
Continuous integration
Two rules that make CI mean something
nobody pushes to
maindirectlythe only way in is a merge request, merged only when the checks are green
Test-driven development
…but it isn’t free
Works best on new code, where you already know what you want.
Over to you
Write tests, refactor behind them, then build a feature test-first.