Chapter 18Unit Testing and Mocking

Unit testing is essential for metaprogramming. However weak the checks performed by a compiler might be in a statically typed language, we don’t have even that level of support in a dynamic language. That’s why unit testing is necessary in dynamic languages. (See Test Driven Development: By Example [Bec02], Pragmatic Unit Testing in Java with JUnit [TH03], and JUnit Recipes: Practical Methods for Programmer Testing [Rai04].) Although we can easily take advantage of dynamic capabilities and metaprogramming in these languages, we have to take the time to make sure our program is doing what we expect and not just what we typed.

There has been greater awareness of unit testing among developers in the past few ...

Get Programming Groovy 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.