BT

Your opinion matters! Please fill in the InfoQ Survey!

JUnit 4.4 Released

| by Ben Hughes Follow 0 Followers on Jul 20, 2007. Estimated reading time: less than one minute |

A note to our readers: As per your request we have developed a set of features that allow you to reduce the noise, while not losing sight of anything that is important. Get email and web notifications by choosing the topics you are interested in.

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 Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Nice 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?

Re: Nice 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

I don't know... 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.

ass hat? 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...

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

4 Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT