Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Boost your Java Test with Ruby and JtestR

Boost your Java Test with Ruby and JtestR

This item in japanese

The ease of Ruby for scripting tasks makes it a very powerful candidate for writing your Test suites. Until recently, there was no real standalone framework to test your Java with Ruby. JtestR written by Ola Blini (a member of JRuby team) and Anda Abramovici makes it possible now.

The main project is a collection of Ruby libraries bundled together with JRuby integration. It also includes the well known libraries in the Ruby world: RSpec (for BDD), mocha (for mocking and stubbing), dust (descriptive block syntax test definition), Test/Unit, and ActiveSupport (Ruby utility classes).

You'll end up with test case looking like this (RSpec wise) :
import java.util.HashMap

describe "An empty", HashMap do
 before :each do
 @hash_map =
 it "should be able to add an entry to it" do
 @hash_map.put "foo", "bar"
  @hash_map.get("foo").should == "bar"
 it "should return a keyset iterator that throws an exception on next" do
 proc do
 end.should raise_error(java.util.NoSuchElementException)
As an Ant task JtestR supports Ant, buildr and Maven2 integration.

Notice that JtestR relies on JRuby (which is still in heavy development) and that if you're running your tests often, you should set up the server Ant task to avoid JRuby heavy startup time (as described in the Getting Started tutorial).

With 0.1.1 version JtestR is in its early releases and your feedback will than welcome to guide its future direction.

Rate this Article