Re: [TFUI] the simplest test that could possibly fail
"Phlip" <[email protected]> Sat, 10 Sep 2005 12:09:10 -0700
| Newsgroups | gmane.comp.programming.test-first-user-interfaces |
|---|---|
| Message-ID | <00e701c5b63b$250bc060$eeddfea9@Marley> |
TFUIers:
I figured out a good answer.
(This is a legitimate revelation: I did not set the first post up as an
"exam question" or "guru of the week" deal...)
> This test fails if my built-in server cannot serve the graphic of the
> mascot
> that goes in the upper left corner of the Wiki:
>
> def test_getPenBird()
> response = Response::get( "http://localhost:8001/images/penBird.gif" )
> assert_no_match /Internal Server Error/, response.body
> end
>
> This test is the simplest that can fail. Some TDD references say "write a
> test that can only pass if you have the feature you want." That sounds
> hard!
Writing simplest tests that can fail is acceptable (and occassionally
passing them with an obvious implementation, then retrofitting more tests
that enforce that implementation is acceptable too...).
But the point of theory is this: A test case should not state in the
negative what it does not want to happen. My test that detects an error is
fine, and we should use it to prevent errors. Don't use many such tests to
drive development.
To drive development, write simple tests that state positively what you _do_
want.
Here's my next test. With more research, it could have been my _first_ test.
It is the simplest thing that could possibly fail, but which states
positively what it _does_ want, not negatively what it does _not_ want:
> response = Response::get( "http://localhost:8001/images/penBird.gif" )
> assert_match /^GIF89aB/, response.body
The difference is trivial to spot: We upgraded assert_no_match() to
assert_match(). We assert that we _do_ want a GIF file in the HTTP pipe.
This is the cheapest _positive_ test that could possibly fail. The test does
not then go into the GIF and detect, using image analysis, that it indeed
portrays the mythical PenBird.
Because other tests will continue to tighten the constraints around this
bird, around GIFs, and around the image serving system in general, this test
is sufficient to drive development.
--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
------------------------ Yahoo! Groups Sponsor --------------------~-->
Most low income households are not online. Help bridge the digital divide today!
http://us.click.yahoo.com/cd_AJB/QnQLAA/TtwFAA/nhFolB/TM
--------------------------------------------------------------------~->
To unsubscribe, email:
TestFirstUserInterfaces-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/TestFirstUserInterfaces/
<*> To unsubscribe from this group, send an email to:
TestFirstUserInterfaces-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/