InfoQ

News

"Literate Testing" for Readable JUnit Tests

Posted by Deborah Hartmann on Jun 15, 2006 02:07 PM

Community
Java,
Agile
Topics
Agile Techniques
Tags
Testing ,
Innovations
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 :-)
TestNG asserts are readable too by Alex Popescu Posted Jun 16, 2006 10:05 AM
  1. Back to top

    TestNG asserts are readable too

    Jun 16, 2006 10:05 AM 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.

Educational Content

Bindings, Platforms, and Innovation

This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.

Orchestrating Long Running Activities with JBoss / JBPM

This article explores the use of JBoss and jBPM to implement design solutions that effectively address the issue of orchestrating long running activities.

Neo4j - The Benefits of Graph Databases

This presentation covers the use of graph databases as an optimal solution for data that is difficult to fit in static tables, rapidly evolving data or data that has a lot of optional attributes.

Realistic about Risk: Software development with Real Options

This session introduces Real Options and shows how it can help in running your project. Real Options is a decision-making process that can be used to manage risk.

Communication Flexibility Using Bindings

This article discusses the use of bindings on services and references (including the instance of non-configured bindings) as the means to implement SCA communications in a Web and SOA environment.

Writing DSLs in Groovy

After a short introduction to DSLs, Scott Davis plays with the keyboard showing how to approach the creation of a DSL by typing working snippets of Groovy code that get executed.

Scaling Agile with C/ALM (Collaborative Application Lifecycle Management)

IBM Rational and InfoQ present, Scaling Agile with C/ALM, an eBook showing organizations how to become “finely tuned software delivery machines” by enabling team integration and scaling.

Concurrent Programming with Microsoft F#

Amanda Laucher presents a real life enterprise application written in F#. She shows actual code snippets, explaining design decisions and suggesting how to use some of the F# constructs.