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, 08 May 2003

Learning tests

Mike Clark writes about learning tests. They're tests he writes to figure out an API. He's made me think about one of my habits.

I tend to use the interpreter for learning. Where Mike describes writing a test to see what the return value of a method is, I would do this:

irb(main):001:0> load 'timeclock-web-services.rb'
true

irb(main):002:0> session = start_session
#<Timeclock::RichlyCallingWrapper:0x358094
@wrapped=#<Timeclock::RichlyCalledWrapper:0x3580bc
@wrapped=#<Timeclock::Server::Session:0x35aa88
@user="web-services-default-user",
@active_job_manager=<ActiveJobManager: {}>, @records=[],
@jobs={},
@persistent_user=#<Timeclock::Server::PersistentUser:0x35a3f8
@user="web-services-default-user">>>>

irb(main):003:0> puts session.methods
last_change_log
last_command
wrapped
method_missing
last_complete_result
...

What does this gain?

  • It's faster than going through a testing cycle. I suspect I ask more questions than I otherwise would, because asking a question is so easy. I'm more apt to explore rather than stick to just what I think I need to know.

  • The interpreter tends to spew out a bunch of info at once. The several lines above show the contents of an ActiveJobManager within a Session within a RichlyCalledWrapper within a RichlyCallingWrapper. So a single question tells me a lot about what's going on, even though the spew is roughly as obfuscated as XML. In contrast, in a test, I get only the answer to the question I think to ask.

What does it lose? (Leaving aside that you can't do it in Java.)

  • You lose the tests and the documentation they provide. (I've never been quite comfortable with tests as documentation - I'd rather go to the code - so I think I underplay that testing role.)

  • Mike mentions extracting code for dealing with the API from the tests. I do some of that, since I will often write a little file of utilities that I load to help me explore. But they don't tend to get preserved and reused.

  • Having a file full of tests probably encourages methodical exploration, whereas an interpreter transcript makes it easier to overlook things. (This is the flip side of the last of the advantages.)

I've done roughly what Mike does, but only (I think) when I'm trying to learn a package preparatory to changing it. That's a different dynamic. I'm acting mostly as a maintainer who wants a safety net of tests, not just as a user of the API. So I think I'll adopt Mike's style next time I want to understand an API. Since Mike's doing some Ruby, maybe he'll try my style. I bet there's a blend that's better than either: a way of rapidly cycling between typing at the interpreter and typing tests in a file.

## Posted at 15:35 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