Boost your Java Test with Ruby and JtestR
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) :
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.
Discuss
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.HashMapAs an Ant task JtestR supports Ant, buildr and Maven2 integration.
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
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.
Community comments
Educational Content
Writing Usable APIs in Practice
Giovanni Asproni May 19, 2013




Hello stranger!
You need to Register an InfoQ account 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