"Untestable" code - Groovy

This is a part of "Untestable code" series. See the introduction to know what is it all about (yes, you really should go there, do it).

The main idea of the series is to write unit-tests for a particularly nasty piece of code. In this part I will use Groovy language to write test cases... well, not exactly. The point is that you can't do it with Groovy. :(

I read about Groovy, and I was amazed by some of its features. Especially the MetaClass magic and some mock/stub features offered by the language itself (and not by some 3rd party libraries). So, I was convinced that I can test such a nasty code (please refer to this blog post) with ease using Groovy. I was wrong.

Hamlet D'Arcy explained in details why you can't do it in Groovy, so I will not repeat it here - go and read his blog post "Testing Java from Groovy? 2 Misconceptions".

It is possible that one day Groovy will support mocking of static calls and new operator. There are two JIRA issues for these functionalities:

Both issues are quite old, and I AFAIK there are not on the "top priority features" list of Groovy roadmap.

[UPDATED 17 December 2009 - 6 months has passed and nothing changed - both issues are still open.]

 
 
 
This used to be my blog. I moved to http://tomek.kaczanowscy.pl long time ago.

 
 
 

Please comment using