"Literate Testing" for Readable JUnit Tests
One thing their teams like is the idea of constraints: now they always use the
org.jmock.MockObjectTestCasebase 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: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.
is more readable and understandable than:
You can read it as "assert that a eq(uals) 3".
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 :-)
TestNG asserts are readable too
.w( the_mindstorm )p.
Caitie McCaffrey Apr 24, 2015