Overview

Chapter 10. Creating acceptance tests with Fit

Fit is presented as a popular acceptance-testing framework that helps bridge the gap between customers and programmers by turning table-based examples into executable tests. The chapter frames acceptance TDD as a three-step collaboration: the customer sketches a test document in familiar language, the team cleans it up so Fit can parse it, and developers implement the fixture classes that connect those tables to the system under test. This workflow keeps the customer’s intent visible while giving the technical team a way to automate verification and produce readable, color-coded results.

The core idea is that a Fit test document is just a mix of narrative text and executable fixture tables, usually in HTML. Fit ignores the prose and processes the tables by matching them to fixture classes, which act as the backing code for the examples. The chapter explains three built-in fixtures in detail: one for simple calculations and expected results across columns, one for comparing sets of returned objects against table rows, and one for modeling actions like starting, entering values, pressing controls, and checking outcomes. Together, these illustrate how Fit can support both state-based and interaction-based testing.

The chapter also shows that Fit is designed to be extended. Custom fixtures can be created to better suit a domain, and FitLibrary adds more powerful options such as flow-style testing and setup-oriented tables that read more naturally. Finally, it covers how to run Fit tests from the command line, across whole folder structures, and as part of automated builds with Ant, emphasizing that acceptance tests are most useful when they are easy to execute and publish. Overall, the chapter positions Fit as a practical tool for collaboration, readable specifications, and automated acceptance testing in real projects.

The transitions from a test document informally described by the customer to an executable test. After the customer has created the initial test document, the development team first sanitizes the tables so that Fit can interpret it correctly. With a syntactically valid test document, the development team next implements the backing code—the fixture classes—so that Fit has something to invoke when processing the test document. When all three of these steps are done, we have an executable test in the form of the combination of a document containing fixture tables and code that implements the tables.
The Fit framework translates the customer’s language encoded in fixture tables into the computer’s language encoded in fixture classes. The fixture classes can be implemented with a variety of programming languages, typically—but not necessarily—in the same language as the system under test is implemented. Scripting languages, for example, are often a good candidate for implementing the backing code for fixture tables due to their flexibility and ability to integrate with other technologies.
Fit test documents are regular HTML files that can be edited with a regular word processor. The example document shown here illustrates how the format allows for mixing executable test or fixture tables with narrative text around them.
The column fixture table from figure 10.4 with explanations of the meaning of key elements of the table structure
Listing 10.1. CalculatorFixture.java
As Fit executes our tests, the relevant table cells are colored to indicate success and failure. For any mismatch, both the expected and actual values are displayed next to each other.
The RowFixture can be used to compare larger datasets easily. The RowFixture compares the set of objects described by the table rows to the set of objects returned by a query method on the fixture class.
Listing 10.2. Example RowFixture verifying that calculator records history correctly
Listing 10.3. The domain object class returned by the query method
RowFixture finds and highlights differences between the expected and actual data by invoking a query method that returns an array of objects, comparing it to the array of objects constructed from the fixture table’s rows. Any surplus or missing records will be highlighted with a pink background while the matching records get the familiar green shade.
ActionFixtures are, as their name implies, action-oriented and are suited for modeling interaction with the system under test. The four available actions to use in the fixture table are “start”, “check”, “enter”, and “press”.
Listing 10.4. CalculatorActionFixture.java
Listing 10.5. Extending ColumnFixture to create a data-population fixture
Example of a test making use of a custom DoFixture and ReviewsDoFixture, showcasing some of DoFixture’s additional features compared to the built-in ActionFixture. Although the document contains multiple fixture tables, they’re all handled by the ReviewsDoFixture, activated with the first table on the page. The remaining tables and rows map to methods on the ReviewsDoFixture instance, except when such a method returns a Fixture. When the method returns a Fixture object, that particular Fixture object handles the remainder of that table.
Listing 10.8. Example of a SetUpFixture
Listing 10.9. Running Fit with an Ant build script

FAQ

What is Fit and why is it used in acceptance test-driven development?Fit is a table-based acceptance-testing framework that helps customers, testers, and programmers collaborate. It lets users describe desired behavior in familiar documents, then automatically checks those examples against the actual system, creating a feedback loop between business and technical stakeholders.
What are the three main steps for turning a customer’s examples into an executable Fit test?The process starts with a customer sketching a test document using example tables, then the team cleans up the tables so Fit can interpret them, and finally the team implements the backing fixture classes that Fit invokes when running the tables.
What is a Fit test document?A Fit test document is usually an HTML file that mixes narrative text with executable fixture tables. Fit ignores the narrative and processes the tables in the order they appear in the document.
What is a fixture in Fit?In Fit, a fixture is the combination of a fixture table and the fixture class that implements it. The table expresses the test in the customer’s language, and the fixture class provides the code that makes the test executable.
How does Fit connect fixture tables to fixture classes?Fit reads the first cell of a fixture table to determine the fixture class name, loads that class, creates an instance using the default constructor, and then feeds the table data to that object according to the rules of the specific fixture type.
What does ColumnFixture do?ColumnFixture maps table columns to public fields and methods on a fixture class. Input columns populate fields, while columns named with parentheses such as result() indicate expected results that are obtained by calling a no-argument method and comparing its return value.
What is RowFixture used for?RowFixture is used to compare a set of expected rows in a table against a set of actual domain objects returned by a single query method. It is especially useful for verifying state or larger datasets rather than simple calculations.
How does ActionFixture work?ActionFixture models interaction-oriented tests using keywords in the first column of each row. Its built-in actions are start, enter, press, and check, which map to creating an actor, sending input, invoking no-argument actions, and verifying return values.
What are DoFixture and SetUpFixture in FitLibrary?DoFixture is a more flexible, natural-language-friendly fixture that allows mixed keyword-and-argument rows and can delegate to child fixtures. SetUpFixture is designed for intuitive setup tables, using the header row to build method names for inserting test data.
How can Fit tests be executed and integrated into a build?Fit tests can be run from the command line using FileRunner for a single document or FolderRunner for a directory of tests. In Java projects, these runners can be wrapped in Ant targets so Fit tests run automatically during the build, and the generated result HTML can be published for review.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Test Driven Test Driven ebook for free
Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Test Driven Test Driven ebook for free