InfoQ

News

JUnit 4.4 Released

Posted by Ben Hughes on Jul 20, 2007

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.

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...

Educational Content

Brian Marick on 4 Challenges and 5 Guiding Values of Agile Software Development

Brian Marick takes us through a quick tour of the most important values and challenges to adopting Agile successfully (they aren't the typical challenges and values we hear in the community).

Are You a Software Architect?

The line between development and architecture is tricky. Does it exist at all? Is an ivory tower actually needed? There's a balance in the middle, but how do you move from developer to architect?

Agile – A Way of Life and Pragmatic Use of Authority

The word 'authority' sometimes produces an allergic response in hard-line agilists. Freedom and authority – both are bad if misused and both are good if used in right spirit for a noble cause.

Getting Started with Grails, Second Edition

"Getting Started with Grails" brings you up to speed on this modern web framework. Companies as varied as LinkedIn, Wired, and Taco Bell are all using Grails. Are you ready to get started as well?

Using ITIL V3 as a Foundation for SOA Governance

Those familiar with only ITIL V2 often scoff at the thought that ITIL could serve as a governance framework for SOA. With ITIL V3, the focus of the framework shifted towards service-orientation.

Adrian Colyer on AspectJ, tc Server and dm Server

SpringSource CTO Adrian Colyer discusses AspectJ, SpringSource's dm Server and tc Server products, OSGi and Scrum.

Adam Wiggins on Heroku

Heroku's Adam Wiggins talks about Rails, Background Jobs, Add-Ons, Ruby, and how Heroku manages to work around Ruby's inefficiencies using Erlang and other languages.

SOA as an Architectural Pattern: Best Practices in Software Architecture

For Grady Booch the foundation of a good architecture is patterns, SOA being just one of many patterns. In this Second Life presentation, Booch attempts to bring more clarity on what architecture is.