4

I am planning to test my Java-based web application using its programming interfaces. To this aim, I intend to call my session beans using their RMI/WebService interfaces and check if their supported services are correct or not. To do this, I need a scripting language to:

  • Call my RMI/WebService interfaces
  • Execute SQL statements (e.g. for cleaning the DB at first)
  • Have a simple flow control (loops, conditions, etc. )
  • Be easy to understand. I may ask my non-programmer staff to write test scripts

I am planning to use Groovy to this aim. Is there any better suggestion or alternative for Groovy?

Edit 1

Other introduced alternatives to Groovy mentioned in answers are JRuby and RSpec. Is there any comparison for them on the web?

TonySalimi
  • 8,257
  • 4
  • 33
  • 62
  • 1
    If you're looking for something better you're not completely satisfied with Groovy, I guess. What's the problem with it? Personally I've been using Groovy to write tests for a java project and it's been a great experience. – Andrew Logvinov Dec 08 '12 at 07:22
  • 2
    have you tried [Spock](http://code.google.com/p/spock/) – tim_yates Dec 08 '12 at 07:34
  • @AndrewLogvinov: I have not used Groovy yet, but this is my first option. I just wanna to know is it OK to use Groovy for my case or I should switch to something else? – TonySalimi Dec 08 '12 at 11:26
  • @tim_yates: Not yet. Thanks for the advice. I should look it deeply. ThanX. – TonySalimi Dec 08 '12 at 11:27
  • RSpec with JRuby is good. A Groovy based testing framework might be preferable if you have Java programmers that don't want to learn a drastically different language. Groovy is a much easier transition for Java devs than JRuby is generally. Also you might check into Cucumber which I believe is Ruby based. – Todd W Crone Dec 09 '12 at 21:25

2 Answers2

6

I think Groovy is the best that you can use for your tests. Groovy integration with Java is seamless, thus calling methods, libraries, and stuff like that usually run smooth.

Also companies which are starting to use Groovy usually start using it for tests, and later use it in production code.

As @tim_yates said, Spock is a Groovy framework for testing and a great one. You can also use JUnit/EasyMock/TestNG/Whatever without problems, and Groovy itself comes with the GroovyTestCase (based on JUnit) which gets the job done.

Groovy also enables you to write cool DSLs, which help you to achieve a programming language for non-programmers, as you said you need.

SQL support in Groovy is also simple. You can use groovy.sql package classes and get started really fast with it, or you can go for JPA if you want.

Will
  • 14,348
  • 1
  • 42
  • 44
1

I would recommend RSpec with JRUby.

RSpec is very clear, descriptive and easy to understand, even non-programmers can use it. With JRuby you can do pretty much everything you can do with Java.

So RSpec with JRuby sounds like a good match for your requirements.

For an example see http://patshaughnessy.net/2009/6/25/taming-the-beast-using-jruby-and-rspec-to-test-a-j2ee-application

user454322
  • 7,300
  • 5
  • 41
  • 52