Back to Basics - Writing Expressive Tests Without All The Wizardry

keywords:
room: Grand Ballroom C North — time: Thursday 09:00-09:45, Thursday 09:45-10:30
Level: Practicing

There are quite a few good tools available for developers who are interested in writing more expressive tests. These cover a broad spectrum from unit testing and mocking frameworks to executable requirements platforms. But sometimes in our excitement for learning new tools we overlook the most useful tool of all…the language features of our chosen programming language. In this session we will get back to basics by exploring how you can write more expressive tests using the language features of Java, the framework features of JUnit, and the practice of Behavior Driven Development.

Process/Mechanics

This talk will primarily be structure around a series of live coding demonstrations that simulate a developer (played by the speaker) new to a code base sitting down, learning about the system through its tests, and eventually adding new features. These demonstrations will be divided into two major parts. In first part a suite of classic JUnit based tests will be iteratively refactored to make them more expressive and to help the developer gain a clearer picture of the system. In the second part the developer will engage in a feature discussion with a Business Analyst and will rapidly capture aspects of the desired functionality into tests written with Java and JUnit.

The goal through of this talk will be to produce tests that are clearly descriptive of the behaviors that the system under test should exhibit. Through this iterative process the following techniques that will be explored include:

  • When/Should naming syntax
  • Method and parameter naming
  • JUnit annotations
  • Hamcrest matchers
  • Static imports
  • Builders

At the end of this process the refactored should clearly express the desired behaviors of the system under test and be understandable by not just other developers, but also testers and business analysts.

Learning outcomes
  • Attendees will leave with an increased awareness that you don’t need a comprehensive tool (such as Fitnesse, easyb, or RSpec) to write expressive tests. These are excellent tools, but sometimes organization, technical, or social constraints prevent their adoption and even in these environments developers can (and should) write good tests.
  • Attendees will leave with a better understanding of many of the techniques for writing expressive tests using just the language features of Java and the features of the JUnit framework.
  • Attendees will leave with a better understanding of Behavior Driven Development and how the re-orientation of the thought process around system behaviors instead of implementation structure better communicates intent and remains relevant longer.
  • Attendees will have observed how requirements can be interactively discussed between developers, testers, and analysts and these conversations captured in tests built using Java and JUnit.
Featured participants
Primary target persona
Reviews

No reviews

Subscribe to an RSS feed of reviews of this proposal Syndicate content