3. About Me
• President and CTO of Third
Wave Technology
• Developing software
professionally since 1998
• Maintainer of a handful of
open source projects (Crux,
physique, build_number)
• Musician and aikido
practitioner
4. About Third Wave
• Boutique consulting firm
specializing in Agile
development
• Develop custom software for a
variety of languages and
platforms
• Strong focus on Agile
practices like Unit Testing and
Continuous Integration
5. What is Unit Testing?
• The practice of writing code to test individual
“units” in isolation.
• Originally conceived by Kent Beck in the
Smalltalk era. Made popular by JUnit.
• One of the pillars of Agile software development.
6. Why Unit Test?
• Speeds up the development cycle.
• Provides a safety net against enhancing or
refactoring existing code.
• Provides a living set of documentation about
how the code really works.
• Helps you write better code.
7. Better Design Through Tests
• Get immediate feedback from your API
decisions.
• Separates interface from implementation
concerns.
• Promotes the Single Responsibility Principle.
• Promotes the YAGNI principle.
(You Ain’t Gonna Need It!)
8. Foundation of Quality
• Unit testing is not a
replacement for other forms of
testing.
• However, it does make testing
easier by reducing uncertainty
in individual units.
• When combined with other
types of automated and
manual testing, you can have
a high degree of confidence in
the software.
9. Unit Testing Styles
• Test Driven Development (TDD) Style typically
structured via Arrange, Act, Assert (AAA).
• Behavior Driven Development (BDD) Style
• Both follow the Four Phase Test Form
Setup - Setup the unit under test.
Exercise - Exercise the unit and capture results.
Verify - Verify that the results meet expectations.
Teardown - Cleanup any side effects of the test.
10. TDD Style
The Good
Clearly shows how the API
will be used in “real” code.
The Caveat
Can lead to bigger tests that
are less self documenting.
11. BDD Style
The Good
Leads to self-documenting
specifications of units.
The Caveat
The test code is spread out
and may be harder to grok.
13. QUnit
http://qunit.js
• Developed by the jQuery
Team.
• Designed for testing in the
browser.
• However, it can be run from
the command line using a
headless browser like
phantomjs.
• Uses a TDD Style.
• Simple, flat syntax.
14. Jasmine
http://jasmine.github.io/
• Developed by Pivotal Labs.
• Designed to run in a DOM-
less environment.
• However, it can run in the
browser.
• BDD Style testing framework
heavily influenced by RSpec.
• Lots of built in features
including a fluent assertion
syntax and spies.
15. Honorable Mentions
• Mocha + Chai - http://mochajs.org | http://chaijs.com
• BDD framework with simple syntax.
• Limited built in features but plays nice with other libraries.
• Chai provides a very nice fluent assertions syntax.
• Jest - https://facebook.github.io/jest/
• Built on top of the Jasmine framework.
• Automatically mocks dependencies.
• Runs your tests using a fake DOM which makes it easy to run your tests
from the command line.
16. Which One Should You Use?
• Do you prefer a BDD or TDD syntax?
• Are you testing code that will always run in the
browser or will it run standalone?
• Are you using an application framework that
prefers one over another?