Skip to Main Content
JRuby Cookbook
book

JRuby Cookbook

by Justin Edelson, Henry Liu
November 2008
Intermediate to advanced content levelIntermediate to advanced
224 pages
5h 2m
English
O'Reilly Media, Inc.
Content preview from JRuby Cookbook

Chapter 7. Testing

Introduction

The focus of this chapter is the topic of automated testing, specifically, testing Java code with Ruby. There are several key advantages of using a dynamic language, such as Ruby, to test code written in a statically typed language, such as Java:

  • Automated test cases tend to require a lot of bootstrapping code. Using a domain-specific language (DSL) such as those provided by the Ruby frameworks like dust and Expectations can cut down on this repetitive code.

  • Dynamic languages make it very easy to create mock objects. JRuby, for example, allows you to directly instantiate Java interfaces.

  • Open classes allow code to be modified at runtime to facilitate testing.

There are a variety of testing frameworks available in Ruby, the most popular of which are wrapped into a JRuby-based project called JtestR. JtestR is an open source project that Ola Bini and Anda Abramovici, developers at ThoughtWorks, started in 2008 with the purpose of making it easy to test Java code with a variety of Ruby testing frameworks. As of the current version 0.3, JtestR includes support for:

  • Test/Unit

  • RSpec

  • Expectations

  • dust

  • Mocha

In addition, JtestR supports the Java testing frameworks JUnit and TestNG, making it a “one-stop shop” for testing frameworks.

JtestR is available for download from http://jtestr.codehaus.org.

Unit Testing Java Code with Test/Unit

Problem

You want to test your Java code using a more concise syntax than is available from Java testing frameworks such as JUnit and TestNG, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Ruby Cookbook, 2nd Edition

Ruby Cookbook, 2nd Edition

Lucas Carlson, Leonard Richardson
Groovy 2 Cookbook

Groovy 2 Cookbook

Andrey Adamovich, Luciano Fiandesio
Mastering Ruby Closures

Mastering Ruby Closures

Benjamin Tan Wei Hao
Ruby Phrasebook

Ruby Phrasebook

Jason Clinton

Publisher Resources

ISBN: 9780596155063Errata Page