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

Bindings, Platforms, and Innovation

This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.

Orchestrating Long Running Activities with JBoss / JBPM

This article explores the use of JBoss and jBPM to implement design solutions that effectively address the issue of orchestrating long running activities.

Neo4j - The Benefits of Graph Databases

This presentation covers the use of graph databases as an optimal solution for data that is difficult to fit in static tables, rapidly evolving data or data that has a lot of optional attributes.

Realistic about Risk: Software development with Real Options

This session introduces Real Options and shows how it can help in running your project. Real Options is a decision-making process that can be used to manage risk.

Communication Flexibility Using Bindings

This article discusses the use of bindings on services and references (including the instance of non-configured bindings) as the means to implement SCA communications in a Web and SOA environment.

Writing DSLs in Groovy

After a short introduction to DSLs, Scott Davis plays with the keyboard showing how to approach the creation of a DSL by typing working snippets of Groovy code that get executed.

Scaling Agile with C/ALM (Collaborative Application Lifecycle Management)

IBM Rational and InfoQ present, Scaling Agile with C/ALM, an eBook showing organizations how to become “finely tuned software delivery machines” by enabling team integration and scaling.

Concurrent Programming with Microsoft F#

Amanda Laucher presents a real life enterprise application written in F#. She shows actual code snippets, explaining design decisions and suggesting how to use some of the F# constructs.