Break
Unit Test Writer’s Block – The Code
Agile in a Flash by Jeff Langr and Tim Ottinger
(card #50)> Test that you can call the method at all
> Pick the most interesting functionality
> Pick the easiest functionality
> Write an assertion first
> Rename or refactor something
> Switch programming partners
> Reread the tests and code
--
Software authors can also get writers block. A good trick to beating it is to do some useful programming activity to get the creative juices flowing.
In legacy code, calling a method at all can require considerable setup, mocking, and dependency breaking. These activities get you entrenched in the code and activate your urge to clean up the code base.
Let your curiosity guide you. Test the most interesting bit of the functionality you’re writing. You’ll have more energy to do work that interests you most.
Alternatively, pick the easiest functionality so that you experience some success and build momentum. “Simple is as simple does.”
When writing a method normally (begin-to-end) fails, try writing the assertion first and working backward from there.
If you rename or refactor something, you’ll have your head wrapped around the problem more and end up with a code improvement to boot!
If the flow of ideas is getting stale, “a change is as good as a break,” so switch programming partners.
You may be stuck because you don’t really understand the code you need to change. Help your brain: reread the tests and code that already exist.
--
“Don’t waste time waiting for inspiration. Begin, and inspiration will find you.” ― H. Jackson Brown Jr.
No comments:
Post a Comment