September 12, 2006 2:15 pm
Code does:
Sequencing: performing actions in a certain order.
Logic: performing actions according to logic.
Transformation: changing data from one form to another.
Utility: getting some data from some other data, eg: "cat,dog,horse".split(",").
State: removing from, adding to or changing state.
Hardware interaction: keyboards, screens, ports, hard disks, etc.
Library interaction: talking to libraries, systems or drivers that encapsulate the above.
If your method or class does more than one of these things, such as performing transformations in a particular sequence, then maybe that’s a good place to start refactoring new methods. Or new classes.
Disclaimers:
The list may not be complete; if you can think of anything else that code does, please let me know!
I’m sure this list isn’t original, but I’m not sure where I got it from. My terminology may not be standard.
This list was prompted by Simon’s post on the Rules of Engagement for using mocks (or not). I agree with Simon that:
Sometimes, though, we really care about the interaction. Not all of the actions above can be defined using stubs. For this reason, and in the spirit of Sun Tzu, who said something like “Win the war before you fight it,” I hereby present my own Rules of Engagement.
public class SheepTest extends TestCase {
public void testShouldEatAnyAvailableGrass() {
//TODO
// or fail("TODO"); if you want to remember to do it before you check in
}
}
I can do this before I code my sheep, and implement the real class when I’m done with its customer. This helps deal with Simon’s rule 1.
I really love mocks. š
Posted by Liz
Categories: Uncategorized
Tags:
Mobile Site | Full Site
Get a free blog at WordPress.com Theme: WordPress Mobile Edition by Alex King.