Jun 26, 2010 Comments Off
PPL: Day 13 – Unit Tests
This is part of the Peer Pressure Learning 30 series. Get a handle on this PPL thing with my introduction to the experiment.
It’s the weekend, so I’m back to the evening groove. The morning was relaxed and the whole family and I went to visit the Amish farm that we buy all our meat, eggs, and chicken from. But that’s another blog post.
Today’s posts is on unit tests. I’m trying not to be a snob as the Ruby community seems to really have testing nailed. Between Rspec and Cucumber, I’m in heaven. I have to remind myself that there’s a lot to learn from the Java community and especially about writing good tests.
Today’s reading: pg 121 – pg 134
Uncle Bob seems to nail me with every chapter. I have been, for the most part, a self-taught programmer. The programming courses I took in college were a joke that I dominated in my sleep, so I jumped over to a business degree so I could learn something I didn’t know. But therein lies the problem. Until now, I’ve never had a systematic approach to polishing my craft. This line from the text describes me to a T:
…in the mad rush to add testing to our discipline, many programmers have missed some of the more subtle, and important, points of writing good tests.
Some really good points come out of the chapter:
- Test code should match the code quality of production code – I can relate here…test code changes all the time as the requirements change. If your tests are crap, you’ll pay for it every time you have to rewrite tests. Changing over to using Factories has been a perfect example. The tests stay DRY and have been much easier to maintain since the change. Uncle Bob (the author) correctly says: “Test code is just as important as production code.”
- Tests give you courage – That’s a weird thing to say, and it’s definitely my interpretation of the text. But…it really is true. I have tremendous faith in the test suites I use in each of my apps. Because of the safety net they provide, I can rename large models, change big chunks of logic, or refactor sections of tricky code without fear. My tests tell me when I’m done! I couldn’t go back to a non-TDD (test driven development) language ever again (or one with sucky TDD tools). I really mean that. I’d be hard as hell.
- One assert per test…probably – I like that Uncle Bob feels free to break the rules. While it’s a good goal to shoot for one assert per test, the added code and duplication may negate the benefit. I find that I frequently pair a record count assert with an assertion about what’s in the record. The better guideline is to test one behavior (the text says, “concept”) per test.
All in all, I feel pretty good about where I stand with test code. I definitely need to hone my comfort level with the tools I use, particularly to reduce duplication.
I’m totally pumped about tomorrows reading which begins a journey into the depths of classes and their proper composition.
If you’re ready to melt your brain on some wild code stuff, read Miles’ post on Factor, a crazy weird stack language that’s unlike anything you’ve even seen.
During my 5-year stint at a local cabinet shop, I had enjoyed the opportunity to design and install two completely different office setups; one standing-height workstation and the other a traditional L. When I started Literacy5 a year and a half ago, I went through a variety of setups before I settled on something I really liked (some through necessity, and others out of a need to experiment).
One of the most valuable lessons from reading Mitch’s office FAQ was the way he created different spaces for his coding and administrative/non-computer work. In my original office layout, I used the corner section to setup my Mac Pro and three 22″ screens. The large bowed section functioned as my admin area. This worked REALLY well. My computer workstation area stayed immaculately organized while the admin area was always strewn with papers. That gave me the ability to keep extremely focused on the work at hand while coding, with zero distractions. When working on the business side of things, I could multi-task and juggle whatever I needed. My Macbook accompanied my to the admin area whenever I did my bookkeeping.
Now that I spend the days at a shared office, my home office needs have changed dramatically. We are selling our 6,000 sq/ft home/office and will share office space with our friends John and Betsy at a converted warehouse. The office will primarily support managing our home, helping out with the non-profit we do accounting for, and my side projects. I may not even keep a computer there full-time, instead relying on my Macbook Pro. The new layout will still have two separate workspaces, but they will likely be split between my wife and I. I may even setup a dedicated podcast/screencast recording area so that I can leave my mic setup and ready to go.
I’ve had the opportunity to change my desk around, changing out a long 6ft table arrangement for an L-shaped workstation. It fits my monitor setup significantly better and affords a lot more space. I still stick to a clear work area, although it’s nice to have room for notebooks and printouts as needed.



If that’s you, I expect you to contact me in the next 2 minutes. You’ll find a
Yes, I build killer web sites and online software. They’re perfect for my clients not because the technology is great. It’s that they do what no one else could figure out how to do: accomplish my client’s goals of more revenue, more customers, fewer errors, etc.