File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Groovy and the fly likes Unit Testing with Groovy? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Unit Testing with Groovy?" Watch "Unit Testing with Groovy?" New topic
Author

Unit Testing with Groovy?

Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
I am considering writing more Groovy code and feel that a good start would be to write at least unit tests using Groovy (initially testing Java code).
When writing Java unit tests, the tools I mainly use are TestNG, EasyMock and Hamcrest.
I have done some investigation and come to the following results:
- No Eclipse support for writing unit test in Groovy using TestNG.
I guess I can make do with JUnit 4, for the time being.
- The built-in support for mocking and stubbing in Groovy does not exactly feel rock solid - see earlier posts and:
I also fear that there may be problems if, for instance, using the meta class technique for both metaprogramming and for mocking/stubbing. For instance, if I use the ExpandoMetaClass to add new methods at runtime and then, in my unit tests use mocking based on manipulating the meta class, with the result that the new methods added at runtime become unavailable to the unit test.

So, is there anyone that writes unit tests in Groovy and have any experiences to share?
The main motivation for this is an increase in productivity - is anyone able to confirm this?
Thanks and best wishes!
manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
the definitely best IDE for groovy support is IntelliJ. the upcoming free open-source edition from IntelliJ is also supporting it.

for creating test-doubles you do not need easy-mock. due to the dynamic nature of groovy there are other alternatives

some links:
http://groovy.codehaus.org/Unit+Testing
http://docs.codehaus.org/display/GROOVY/Groovy+Mocks


aldana software engineering blog & .more
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
manuel aldana wrote:the definitely best IDE for groovy support is IntelliJ. the upcoming free open-source edition from IntelliJ is also supporting it.

I have tried IntelliJ but while it is nice, I am not that impressed. Eclipse has become much better, as of lately. Also, unit testing and mocking does not really depend on the IDE - of course, if there is a good plugin to integrate the unit testing into the IDE then it indeed makes a difference.

for creating test-doubles you do not need easy-mock. due to the dynamic nature of groovy there are other alternatives

I know that and I was asking about the other alternatives. I have even tried to write some code to become acquainted with the alternatives, but I am not impressed - see my original post above. I was wondering what people with concrete experience of writing unit tests using Groovy have settled for regarding mocking etc.
My requirements to be able to test and mock Java classes from Groovy unit tests may be a little special.
Best wishes!
manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
sorry, i overread some details (that you want test java-code).

regarding productivity: though i like dynamic typed languages, for my side when testing java-code i also test in java. when using java i use a lot of static-typed-based automated refactorings and also want to let "safe-refactor" my test-code. i once tried to use groovy as test-language but the refactorings often broke my tests. therefore i had to touch them.

there is one exception for integration testing, which are more coarse grained: here i often refer to groovy test scripting (examples 'canoo webtest' or 'soap-ui' groovy integration). they are automation-testtools for webapps and SOAP-api.

I know, IDEs have nothing to do with testing frameworks, but coding test-code in groovy (junit,testng) is best possible and supported on IntelliJ.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Thanks a lot for your answers!
Refactoring-safe tests is a very valuable point - just the kind of experiences I were looking for.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unit Testing with Groovy?