I am considering writing more Groovy code and feel that a good start would be to write at least unit tests using Groovy (initially testingJava 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 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.
Joined: Dec 29, 2005
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.
Joined: Oct 04, 2006
Thanks a lot for your answers!
Refactoring-safe tests is a very valuable point - just the kind of experiences I were looking for.