Skip to content

Instantly share code, notes, and snippets.

@nandilugio
Created November 15, 2019 17:45
Show Gist options
  • Save nandilugio/b8b2f7424f0d848e40cfb78137350619 to your computer and use it in GitHub Desktop.
Save nandilugio/b8b2f7424f0d848e40cfb78137350619 to your computer and use it in GitHub Desktop.
Life of your developers
Dev receives a feature request
Add calculator to app
Dev designs the solution
Your average dev
- Calculator.Form
- Calculator.FormController
- calculate
- add
- subtract
- ...
Your testing dev
First ideas:
- Calculator.Form
Test... ok
- Calculator.FormController
- calculate
- add
- subtract
- ...
Test
- render: already done => ok
- calculate: ok
- add? no sense!
Redesign!
- Calculator.Form
- Calculator.FormController
- render
- calculate
- Calculator.Calculations
- add
- subtract
- ...
Difference: Testing yields better code architecture
Dev starts coding
You average dev
- Writes some code
- Starts app in local
- Loop
- Opens the app and navigates to where the calc should be <- SLOW!
- BOOM!
- Fixes something if understands the problem <- difficult: many potential causes
- Debugs if not:
- Goes to the code and adds some print statements <- potentially difficult (may need to log)
- Opens a debugger (and the app, and navigates to where the calc should be...)
Your testing dev
- Writes a test
- Loop:
- Runs it <- FAST!
- BOOM!
- Fixes something if understands the problem <- easier: test focuses on SUT
- Debugs if not:
- Opens a REPL and plays with the SUT
- Goes to the code and adds some print statements <- easier: normally prints are enough
- Run a debugger? practically never in unit tests, rarely on broader integration scopes
Difference: Testing makes development FASTER
Dev has something done, but inadvertently broke something
Your average dev
Continue as nothing happens :)
Your testing dev
- Since there is something ready, dev commits and pushes
- Test suite runs on CI
- BOOM!
- Fixes the issue
- Runs the tests again (locally if possible)
- Pushes working code to repo
Since it has a better abstraction and it works, we can MR to develop, ensuring:
- Other devs can use this code (e.g. Calculator.Calculations)
- Other devs, when they refactor, take this code into account => less merge conflicts or phantom incomplete refactors (e.g. refactor Controller.show -> Controller.get)
Difference: Testing prevents regressions and improves team collaboration
Dev integrates metrics to his development
Your average dev
- Checks another controller
- Finds that the metrics are done with the Metrics module
- Looks for docs on Metric... finds none
- Asks someone... responds RTFM bro!! check the wiki (and gives a link since it's completely buried)
- Reads the wiki
- Implements as wiki says
- BOOM! (wiki was outdated)
- Copy&pastes the metrics code from another controller
Your testing dev
- Checks another controller
- Finds that the metrics are done with the Metrics module
- Looks for tests on Metric
- Implements, and takes profit of all relevant features
Difference: Testing ensures up-to-date documentation of our code, helping devs use it to it's full potential
Dev didn't like the Metrics module too much
Your average dev
Leaves it as is, since it'd be dangerous to refactor it
Your testing dev
Refactors fearlessly, since the tests cover dev's back
Difference: Testing prevents accumulation of technical debt
Dev finishes, and integrates to develop, but undetectable merge conflicts occur
Your average dev
Continue as nothing happens :)
Your testing dev
- Test suite runs on CI
- BOOM!
- Fixes the issue
Difference: Did we state testing prevents regressions?
Release is done
Your average dev
Remember when dev inadvertently broke something?
- BOOM! on customers face...
And the undetectable merge conflicts?
- DOUBLE-BOOM!! on customers face again...
Your testing dev
- Opens the metrics app
- Calculates revenue from new feature
- Asks for a raise (and gets it, business is happy)
- Rejoices
Difference: Testing yields happy people
In summary, testing yields
- Better code architecture
- Easier to maintain
- More extensible to respond quickly to new business requirements
- More flexible to quickly adapt to business changes on requirements
- ...
- Faster delivery
- Product stability
- Less technical debt
- Up-to-date documentation
Testing is like any other tool
You need to learn how to use it
But then, you'll be more effective with it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment