The Artima Developer Community
Sponsored Link

Java Buzz Forum
Nothing is too trivial to test

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Charles Miller

Posts: 1014
Nickname: carlfish
Registered: Feb, 2003

Charles Miller is a Java nerd with a weblog
Nothing is too trivial to test Posted: Sep 30, 2008 11:29 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Charles Miller.
Original Post: Nothing is too trivial to test
Feed Title: The Fishbowl
Feed URL: https://fishbowl.pastiche.org/atom.xml
Feed Description: tail -f /dev/mind > blog
Latest Java Buzz Posts
Latest Java Buzz Posts by Charles Miller
Latest Posts From The Fishbowl

Advertisement

It was really trivial code. A wrapper around a HashMap (dictionary) to temporarily cache some values that were getting too expensive to calculate every time. While writing it, I pretty much convinced myself that this code was so simple there was really no point writing unit tests, but as I got close to checking the code in I realised that the first thing my code-reviewer would ask was “where’s the test?”

So I wrote a test. And it failed. It failed because I'd made a really dumb typo in the constructor of one of the nested classes I was using as cache keys, writing this.username = (user == null) ? null : username instead of this.username = (user == null) ? null : user.getName(). This simple mistake meant my cache would be at best useless, and far more often entirely inaccurate.

Lessons for the day, there are two:

  1. Nothing is too trivial to test
  2. Even the mere threat of a code-review leads to better code

Read: Nothing is too trivial to test

Topic: Disucssion & Examples: Java enums versus public static final Previous Topic   Next Topic Topic: MapReduce programming with Apache Hadoop

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use