Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 411
Olimpiu POP Avatar asked Mar 20 '13 09:03

Olimpiu POP


2 Answers

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!

like image 112
Will Avatar answered Nov 15 '22 15:11

Will


I think it should be read as Groovy is especially good for writing tests compared to Java. There is nothing in Groovy you cannot do in Java, but it would often take tremendous effort. Something like Spock for example, would be near unreadable in Java.

It is many small things that make it so. There are for example power asserts, that make the output of assertion errors from assert statements in Groovy very nice. The seamless integration allows not to have extra code to align the languages worlds. The DSL capabilities allow you easily to write minimal DSLs to reduce the boilerplate code. All this is there to enable you to see what you actually test and how. Because if a test fails, you have to understand that part exactly and it reduces the time you need to spend on writing tests.

All I can advise is trying it out for a bit. It then either convinces you or not. If your cases are very simple, then maybe Java is good enough for you. If the testing gets more complex, then having to understand some Groovy code could be the smaller hurdle here. Not to forget: as a Java developer you don't need to understand all too much about Groovy to be able to use it properly and write nice unit tests with it.

like image 20
blackdrag Avatar answered Nov 15 '22 13:11

blackdrag