BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News JUnit 4.4 Released

JUnit 4.4 Released

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.

Rate this Article

Adoption
Style

BT