BT

Boost your Java Test with Ruby and JtestR

by Sebastien Auvray on Jan 07, 2008 |
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 = HashMap.new
 end
 it "should be able to add an entry to it" do
 @hash_map.put "foo", "bar"
  @hash_map.get("foo").should == "bar"
 end
 it "should return a keyset iterator that throws an exception on next" do
 proc do
 @hash_map.key_set.iterator.next
 end.should raise_error(java.util.NoSuchElementException)
 end
end
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.

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT