jQuery Conference: San Francisco Bay Area 2011



  Natural Language UI Testing
            Using
 Behavior-Driven Development
             With Pavlov and QUnit
Eric DeLabar
• Solutions Architect at Trifecta Technologies
• http://www.trifecta.com/
What’s Behavior Driven
   Development?
        (BDD)
“BDD is a second-generation, outside-in,
pull-based, multiple-stakeholder, multiple-
scale, high-automation, agile methodology.
It describes a cycle of interactions with
well-defined outputs, resulting in the
delivery of working, tested software that
matters.”
                                 -Dan North
What is Pavlov?
Behavioral API over QUnit
       by Michael Monteleone


http://github.com/mmonteleone/pavlov
The Goal:

The login form

 should progressively enhance a form by id.

 should hide a field label when the field has focus.

 should show a field label when the field is empty when the cursor leaves.

 should keep a field label hidden when the field is not empty when the cursor leaves.

 should validate that the email field is valid when the cursor leaves.

 should submit the form when the user clicks the Join button.

 should submit to the action URL of the form with an AJAX POST.
Format spec for Pavlov:
Spec HTML (head)
Spec HTML (body)
First Test
Make it Pass
Second Test
Make it Pass
Third Test
Make it Pass
Fourth Test
Make it Pass
Fifth Test
Make it Pass
Sixth Test
Make it Pass
Seventh Test
Adding Mockjax
Make it Pass
Finished!
What’s Next?

• Add a new Feature?
• Make it better, faster, lighter?
• Fix a bug?
• Cross-browser testing?
Real World Usage

• Major National Corporation
• 3 different mobile web applications
• 3 separate schedules & deployment dates
• Shared custom library + jQuery Mobile
Other Features


• Custom Assertions
• Expected Exceptions
• Run from Command Line or CI Server
Future of Pavlov
• Testing-framework-neutral refactor in-
  progress
  • coming soon: support for YUI2 and 3
  • Try it now: framework-agnostic branch on
    GitHub
  • Ironically enough, needs more test
    coverage
Materials

• Example Code on GitHub:
  https://github.com/edelabar/jqconf2011-pavlov-talk


• Slides on SlideShare:
   http://slidesha.re/fOmeBF
Questions/Comments?

• Twitter @edelabar
• Email: edelabar@gmail.com
• SpeakerRate: http://spkr8.com/t/7239

Natural Language UI Testing using Behavior Driven Development with Pavlov and QUnit

Editor's Notes

  • #2 \n
  • #3 Who writes tests for their JavaScript?\n\nAny Ruby programmers? Ever use RSpec?\n
  • #4 I don’t know what that means...\n\nBDD is a test-driven-development methodology. \n\nWrite tests.\nWrite code to pass the tests.\nThat’s it.\n\nRed, Green, Refactor.\n\nMake sure it fails first, if it doesn’t how will you know if it’s a good test? (Red Step)\n\nWrite only enough code to make it pass. (Green Step)\n\nLater, if you need more functionality, refactor, and make sure all of your old tests still pass.\n
  • #5 Anybody heard of it?\n
  • #6 Inspired by Screw.Unit and RSpec but with QUnit compatibility (so you can use it with QUnit’s existing support for JsTestDriver and TestSwarm)\n\nMIT License\n\n
  • #7 Build a small login form for a web application, the kind with labels in the text boxes that disappear on focus\n\nIt should work without JavaScript enabled, but if we do have it we’ll take advantage of it\n\nMarkup and concept roughly based on Making Compact Forms More Accessible by Mike Brittain from A List Apart\n\nConvert this Spec into a test suite\n\n\n
  • #8 \n
  • #9 \n
  • #10 isLessThan20ButGreaterThan10\n\nTestSwarm\nJsTestDriver\n\n\n
  • #11 In-progress refactor to be testing-framework neutral, coming soon YUI2 and YUI3\navailable in the framework-agnostic branch on GitHub. \n\nWill retain backwards compatibility.\n\n\n\n\n\n\n\n
  • #12 \n