Modern Tools for Unit Testing

by Marco Liberati

Why test JS code?

  • It makes you confident about your code
  • Helps understand the design of the code
  • You want to make big changes quickly

Why test JS code?

  • It makes you confident about your code
  • Helps understand the design of the code
  • You want to make big changes quickly
  • Because each browser has its own dialect*
*vendor prefixes, different implementation of features, etc..

What we want to test?

What we want to test?

What we want to test?

One problem per time...

Starting with the basics:

Assertion Library

  • Pretty much the same functionalities
  • Most of them will work for IE9+
  • If you have to test IE6 IE7+ there’s a single choice: expectJS

Framework

Assertion Library

  • Choose an assertion style
  • Choose a reporter style
  • Write the tests
  • Run the framework…

Test Runners

Framework

 

  • Take your tests
  • Choose a bunch of browsers
  • Run them in parallel!
  • See the reports

Test Runners Workflow:

  1. Preprocess tasks
  2. Add frameworks and assets
  3. Use launchers to spawn browsers
  4. Call the reporters when finished

Browsers

100+ combinations to test!

Browsers

100+ combinations to test!

... but we don't give up!

Browsers

Firefox

Browsers

Chrome

Browsers

Safari

Browsers

Internet Explorer

Browsers

PhantomJS

Extras!

ChaiJS

Code Coverage

Selenium 2

...and now some code!

Any question?

Credits