Test-driven JavaScript development with YUI

Notes from “Test Driven Development with YUI Test” presentation given by Nicholas Zakas

  • Flow:
    1. Define requirements
    2. Write tests to verify requirements are met
    3. Write code to test
    4. Run tests
    5. If test succeed, repeat from step 1 until project is finished. If tests fail, repeat from step 3 until tests pass, and then repeat from step 1 until project is finished
  • Motivations:
    • Even small changes can break a complex app.  Use unit tests and suites of tests to ensure app integrity after each change to the code base.
    • Tasks become well-defined using this methodology
    • We are best positioned to perform QA because we know our code best
  • Tips & tricks:
    • Use a test template to speed up the process
    • Use setUp and tearDown functions to prepare and clean environment, respectively, after each test is run
    • Develop the habit of creating files for code and tests for the code in pairs, e.g. code.js & test_code.js
    • In general, each method gets a test and each object gets a test case
    • In your build process, define a “test” state that inserts YUI test code into the app code base
  • References: