BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

"Literate Testing" for Readable JUnit Tests

| by Deborah Hartmann Preuss on Jun 15, 2006. Estimated reading time: less than one minute |
Brian Marick, a frequent writer on Agile software testing, has reported that Robert Chatley and Tom White are working on sentence style for testing in Java, to make tests easier to understand. They call it "Literate Testing".

One thing their teams like is the idea of constraints: now they always use the org.jmock.MockObjectTestCase base class rather than junit.framework.TestCase, even when they aren't mocking anything out!  Here's an example from Tom White:
We can use constraints to construct more flexible assertions:
assertThat(a, eq("3"));

is more readable and understandable than:
assertEquals("3", a);

You can read it as "assert that a eq(uals) 3".
In a subsequent entry, White introduces the concept of anaphor, a word used to avoid repetition. When judiciously used, in a situation where there is no ambiguity to obscure the reference, it can increase test readability.

Small tricks like changing IDE settings are also used increase readability.

Robert Chatley has recently taken the idea of literate testing further and applied it to functional (acceptance) tests.

And now, we've come full circle:  Chatley tells us that Marick is in the sentence structure game, now, too :-)

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

TestNG asserts are readable too by Alex Popescu

TestNG has done a similar shift a long time ago. JUnit users were used with assertions in the form: assertEquals(expectedValue, computedValue [, reason]). We have considered that it is more readable (even if some of TestNG users considered it dangerous) as in assertEquals(computedValue, expectedValue [, reason]) with its English form: "assert that computedValue equals the expectedValue because reason". However, we still offer the JUnit assertion mode (see Assert and AssertJUnit).

./alex
--
.w( the_mindstorm )p.

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

1 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