At the Code Retreat run at Movio this weekend we watched Corey Haines do the
Roman Numerals kata in Ruby. An
interesting thing he did was to list all conversion in a hash and iterate over
it to dynamically create the test for each conversion:
Later while attempting to create Conway’s Game of
Life using TDD I came
across some tests that were repetitive in a similar manner:
It turns out that ScalaTest also supports creating tests using the same style:
It might take some getting used to, but I think it’s a rather nice way to run
different inputs for the same test. It lets you isolate each input into its own
test case without any code duplication and concisely lists all your test cases
and expected outputs together.
You can see how I did Corey’s Roman Numerals kata in Scala (along with other
katas I have done/will do) on my GitHub.