- assertThat – provides more readable (and flexible) tests using the value/matcher pattern (as introduced by the xMock frameworks), allowing for more readable error messages.
- 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.
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.
The latest release is available for download, as is the updated cookbook.
Community comments
Nice
by Sandeep Khurana,
Re: Nice
by Alex Popescu,
I don't know...
by Joe Wolf,
ass hat?
by Jason Carreira,
Nice
by Sandeep Khurana,
Your message is awaiting moderation. Thank you for participating in the discussion.
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,
Your message is awaiting moderation. Thank you for participating in the discussion.
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,
Your message is awaiting moderation. Thank you for participating in the discussion.
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,
Your message is awaiting moderation. Thank you for participating in the discussion.
I've probably been reading Hani's blog too long, 'cause assertThat looked like "ass hat" to me when I first looked...