Search code examples
javagroovycontinuous-integrationintegration-testingjava-ee-6

What are the benefits of using groovy for writing integration tests for java applications?


I seen a few posts (for instance here 1) suggesting to use groovy to write integration tests for java applications in groovy programming language. I am working on an application using the following technologies: Java 7, java EE 6, POSTGRESQL

I know groovy is

  • easy to integrate with java
  • quick to write code

But is there any particular reason to use it for ITs? Adding another programming language to your codebase would not make your life hell? I think I am missing something from the picture, so I would appreciate your responses.


Solution

  • I will soon start a project with exactly the same stack as yours, but Groovy will also be in production code, not only tests.

    There is no problem in adding Groovy to your codebase, because it is an easy language. It'd be a different story if you were including some language which doesn't look a lot like java, say haskell or prolog. You are already including Facelets, EL, CSS, HTML and Javascript. Which part of adding another language is bad? :-)

    The main points i pick up for Groovy in IT tests:

    • Easy to write assertions and mock data;
    • Conciseness in code;
    • Smooth learning curve;
    • Concise code to operate a browser automation like Geb;

    Other just-to-cool-to-forget stuff in Groovy:

    • Easy to write XML/JSON (if you need test webservices, for example);
    • Static compilation, if you need;

    We had test teams in my two last companies which weren't working in production code, but started writing tests in Groovy pretty quickly and enjoyed the language: no worries about types and stuff, just working tests!