Exploration Through Example

Example-driven development, Agile testing, context-driven testing, Agile programming, Ruby, and other things of interest to Brian Marick
191.8 167.2 186.2 183.6 184.0 183.2 184.6

Thu, 15 Jun 2006

Irony

I'm practicing for a set of five demos I'm doing next week. In each, I'll work through a story all the way from the instant the product director first talks about it, through TDDing the code into existence, and into a bit of exploratory testing of the results. Something interesting happened just now.

Step one of the coding was to add some business logic to make a column in a Fit table pass.

In step two, I worked on two wireframe tests that describe how the sidebar changes. These tests mock out the application layer that sits between the presentation layer and the business logic.

What remained was to change the real application layer so that it uses the new business logic. That, I said (imagining my talk), is so simple that I'm not going to write a unit test for it. Even if I do mess it up (I claimed), I have end-to-end tests that will exercise the app from the servlets down to the database, so those would catch any problem.

You can guess the results. I made the change and ran the whole suite. It passed. Then I started up the app to see if it really worked, and it didn't. The problem is in this teensy bit of untested code:

      def may_add_user?
        Model::Permissions.new.may_add_user?(@current_sesssion)
      end

The problem is that I have an extra s in @current_sesssion. In Ruby, a previously unmentioned instance variable has value nil. It happens that, to the business logic, nil means "no session, so not logged in, so not allowed to create a user."

From this, we can draw two lessons:

  • Maybe all those people who say that even code within a class should go through accessors to get to instance variables are right. Had I done that, the program would have failed—in the end-to-end tests—with a "no such method" error.

  • Hey, one-time program chair of the Pattern Languages of Programs conference, there's this pattern called Null Object...

I'm still not inclined to write a unit test.

This is the neatest thing to happen to me today. But nothing like it better happen in the real demo.

## Posted at 20:09 in category /coding [permalink] [top]

Wireframe style for tests

Earlier, I wrote about sentence style tests for rendered pages. Based partly on conversations about that entry with Steve Freeman and partly on bashing against reality, I've changed the style of those tests.

Since they are about the part of the app that the user sees and since I'd like them to be readable by the product director, I found myself asking where they would come from in a business-facing-test-first world and how the product director would therefore think about them. I imagined that, sometime early on, someone makes a sketch, paper prototype, or a wireframe diagram. So I came to think that this test ought to be a textual, automatically-checkable wireframe diagram. Like this:

  def test_structure_without_audits_or_visits
    wireframe_looks_like {
      page.has_two_columns.and_all_forms_use_the_session_id.
                           and_all_links_use_the_session_id_except_help
 
      page.title.has_id(:patient_display_page).
                 and_includes(:current_animal).
                 and_includes(:current_client)
 
      page.main_text.has_no_list_named(:visits).
                     has_no_list_named(:audits).
                     has_a_form_with_action(:want_add_visit_form).
                     has_a_form_with_action(:want_add_audit_form).
                     has_a_help_popup_named(:patient_display_page).
                     and_no_other_actions
    }.given_that {
      a_user_is_logged_in
      an_animal_has_been_selected
      the_animal_has_no_visits
      animal_treatments_have_never_been_audited
      there_is_help_for_page(:patient_display_page)
    }
  end

One interesting thing is that I put the setup for the test after the checking code. That's because the page layout seems more important.

How well does that test describe this page? (The sidebar is described in tests of its own.)

I'll let you be the judge.

## Posted at 11:45 in category /testing [permalink] [top]

About Brian Marick
I consult mainly on Agile software development, with a special focus on how testing fits in.

Contact me here: marick@exampler.com.

 

Syndication

 

Agile Testing Directions
Introduction
Tests and examples
Technology-facing programmer support
Business-facing team support
Business-facing product critiques
Technology-facing product critiques
Testers on agile projects
Postscript

Permalink to this list

 

Working your way out of the automated GUI testing tarpit
  1. Three ways of writing the same test
  2. A test should deduce its setup path
  3. Convert the suite one failure at a time
  4. You should be able to get to any page in one step
  5. Extract fast tests about single pages
  6. Link checking without clicking on links
  7. Workflow tests remain GUI tests
Permalink to this list

 

Design-Driven Test-Driven Design
Creating a test
Making it (barely) run
Views and presenters appear
Hooking up the real GUI

 

Popular Articles
A roadmap for testing on an agile project: When consulting on testing in Agile projects, I like to call this plan "what I'm biased toward."

Tacit knowledge: Experts often have no theory of their work. They simply perform skillfully.

Process and personality: Every article on methodology implicitly begins "Let's talk about me."

 

Related Weblogs

Wayne Allen
James Bach
Laurent Bossavit
William Caputo
Mike Clark
Rachel Davies
Esther Derby
Michael Feathers
Developer Testing
Chad Fowler
Martin Fowler
Alan Francis
Elisabeth Hendrickson
Grig Gheorghiu
Andy Hunt
Ben Hyde
Ron Jeffries
Jonathan Kohl
Dave Liebreich
Jeff Patton
Bret Pettichord
Hiring Johanna Rothman
Managing Johanna Rothman
Kevin Rutherford
Christian Sepulveda
James Shore
Jeff Sutherland
Pragmatic Dave Thomas
Glenn Vanderburg
Greg Vaughn
Eugene Wallingford
Jim Weirich

 

Where to Find Me


Software Practice Advancement

 

Archives
All of 2006
All of 2005
All of 2004
All of 2003

 

Join!

Agile Alliance Logo