[TIP] "functional paths"

Gary Bernhardt gary.bernhardt at gmail.com
Fri Oct 23 16:04:25 PDT 2009


On Fri, Oct 23, 2009 at 1:21 PM, John J Lee <jjl at pobox.com> wrote:
> On Wed, 16 Sep 2009, C. Titus Brown wrote:
> [...]
>>
>> It would be nice for this if you *could* run JS directly from a Python
>> interpreter
>
> [...]
>
> You can:
>
> http://htmlunit.sourceforge.net/
>
>
> I keep pointing people at this without actually trying it myself, I must try
> it sometime (as it happens, I have a use for it right now, so I have no
> excuse).

I've been doing this on a couple of Django projects with great
success. I use Cucumber, which lets me write executable user stories
in plain English. I hook Cucumber up to Celerity, which is a Ruby
front-end to HtmlUnit that conforms to Watir's API.

This lets me write scenarios like this:

"""
    Given I'm looking at an empty wall
    And there is not a lane named "New Lane"
    And I press "Add Lane"
    Then I should see the lane "New Lane"
"""

Cucumber uses Celerity to execute these with HtmlUnit, including
JavaScript support. They take about 0.5 seconds each to execute on
average (for the *whole* scenario, not each line).

I don't test every little corner case like this, of course – just the
high-level features. For the nitpicky JavaScript bits, I rely on unit
tests written in screw-unit.

I highly recommend all of these packages. It took me less than a day
to set all of this up, including continuous integration with Hudson.
YMMV if you've never touched Ruby, though.

(Also, have I mentioned how much our testing tools lag behind Ruby's? ;)

-- 
Gary
http://blog.extracheese.org



More information about the testing-in-python mailing list