Category Archives: TDD

Fixing date in test using JUnit MethodRule

One of the principles of a good unit test is that they are repeatable. This is especially important if the tests involve dates. Typically this is programmed in the setUp and tearDown of the unit tests. This might lead to duplication if multiple tests depend on such a fixed date. Of course we can abstract this to an Abstract base class, but in the end we all know that reuse via inheritance is a bad idea. JUnit @Rule can be a solution for this.
Continue reading Fixing date in test using JUnit MethodRule

Bowling Game Kata in Ruby

As a good pragmatic programmer you should learn at least one new language per year. For me this year’s (2011) language will be Ruby (I know I am a bit late…). A Kata is an excellent and fun way to learn a new progamming language as well as your (new) IDE or text editor. As Kata I chose the Bowling Game Kata from Uncle Bob. Read on if you want to see how my Bowling Game looks like in Ruby.
Continue reading Bowling Game Kata in Ruby

Organizing test code in Java

A short while back I started to work with Ruby on Rails. Incredible fun and inspiring. One of the (many) things I like is the distinction Rails creates of the different levels of test scopes. It has separate folders to store unit, functional, integration and performance tests.

Now in Java – and using the Maven default folder layout – you get one folder for storing your production code (src/main/java) and one for your test code (src/test/java). That got me to thinking to apply Rails’ way to structure your Java test suite. After a while it can be tricky to organize to test code, so I wanted to give it a shot with Java.
Continue reading Organizing test code in Java