InfoQ

News

JUnit 4.4 Released

Posted by Ben Hughes on Jul 20, 2007 12:57 AM

Community
Java,
Agile
Topics
Unit Testing
Tags
JUnit
The new version of the unit testing suite JUnit has been released and is downloadable from Sourceforge. JUnit 4.4 has some noteable new features:
  • assertThat – provides more readable (and flexible) tests using the value/matcher pattern (as introduced by the xMock frameworks), allowing for more readable error messages.

  • For example:

    assertTrue(responseString.contains("color") || responseString.contains("colour"));
    // ==> failure message:
    // java.lang.AssertionError:

    Becomes:

    assertThat(responseString, anyOf(containsString("color"), containsString("colour")));
    // ==> failure message:
    // java.lang.AssertionError:
    // Expected: (a string containing "color" or a string containing "colour")
    // got: "Please choose a font"


    You can read more about assertThat in Joe Walnes’s blog.

  • Assumptions & Theories (via the assertThat method) enabling the test writer make assumptions in their tests about the environment they’re testing in, useful when testing against an entity outside of the domain of the test.

The latest release is available for download, as is the updated cookbook.

Related Sponsor

VersionOne is recognized by Agile practitioners as the leader in Agile project management tools. Companies such as Adobe, BBC, CNN, Dow, HP, IBM, Sony and 3M have turned to VersionOne to help deliver greater value to their customers.

4 comments

Reply

Nice by Sandeep Khurana Posted Jul 20, 2007 6:04 AM
Re: Nice by Alex Popescu Posted Jul 20, 2007 6:20 AM
I don't know... by Joe Wolf Posted Jul 20, 2007 9:07 AM
ass hat? by Jason Carreira Posted Jul 20, 2007 9:54 AM
  1. Back to top

    Nice

    Jul 20, 2007 6:04 AM by Sandeep Khurana

    Its nice. One question about assumptions, if assumptions are not met(e.g. file separator is not the one mentioned in assumption) then by default test will pass. Is there a to make the test fail..if assumptions are not met?

  2. Back to top

    Re: Nice

    Jul 20, 2007 6:20 AM by Alex Popescu

    Its nice. One question about assumptions, if assumptions are not met(e.g. file separator is not the one mentioned in assumption) then by default test will pass.

    If I am recalling correctly, this is the current behavior but may change in the next versions to ignored.
    If you want your test to fail, then you should use normal asserts and not assumptions.

    bests,
    ./alex
    --
    .w( the_mindstorm )p.
    ________________________
    Alexandru Popescu
    Senior Software Eng.
    InfoQ TechLead&CoFounder

  3. Back to top

    I don't know...

    Jul 20, 2007 9:07 AM by Joe Wolf

    I personally find the assertTrue code more readable than assertThat for the example provided, although the assertThat assertion failure message is much better.

  4. Back to top

    ass hat?

    Jul 20, 2007 9:54 AM by Jason Carreira

    I've probably been reading Hani's blog too long, 'cause assertThat looked like "ass hat" to me when I first looked...

Exclusive Content

Book Except and Interview : Aptana RadRails, An IDE for Rails Development

Aptana RadRails: An IDE for Rails Development by Javier Ramírez discusses the latest Aptana RadRails IDE, a development environment for creating Ruby on Rails applications.

Fast Bytecodes for Funny Languages

Cliff Click discusses how to optimize generated bytecode for running on the JVM. Click analyzes and reports on several JVM languages and shows several places where they could increase performance.

Scott Ambler On Agile’s Present and Future

Scott Ambler, Practice Lead for Agile Development at IBM, speaks on the current status of the Agile community and practices having a look at the perspective of the Agile’s future.

Manager's Introduction to Test-Driven Development

Dave Nicolette and Karl Scotland try to introduce non-technical managers to one of the most popular Agile development techniques: Test-Driven Development (TDD).

Structured Event Streaming with Smooks

Smooks is best known for its transformation capabilities, but in this article Tom Fennelly describes how you can also use it for structured event streaming.

How to Work With Business Leaders to Manage Architectural Change

Successful architectures evolve over time to meet changing business requirements. Luke Hohmann presents how to collaborate with key members of your business to manage architectural changes.

Colors and the UI

In this article, Dr. Tobias Komischke explains how colors used in a GUI can influence our interaction with a computer and offers advice on using the appropriate colors for the interface.

Building your next service with the Atom Publishing Protocol

In his presentation, recorded at QCon San Francisco, MuleSource architect Dan Diephouse explores ways to use the Atom Publishing Protocol (AtomPub) when building services in a RESTful way.