6. Unit tests in JavaScript
Jasmine helps us write formal, executable
specifications. It integrates transparently with
our development methodologies while supporting
us with a set of tools.
6
7. Find them early, fix them cheaply
0
10
20
30
40
50
60
70
80
90
Introduction of defects
7
Cost to fix
11. Formal Specifications
• Formal component specifications
– What is the component supposed to do?
– Executable so always up-to-date
– Specifications “by example”
• Testing is a tool, not a goal
– Alternatives
• Design by contract
• Assertions
• Legacy code: code without tests
– Michael Feathers “Working effectively with legacy code”
– Premature legacy
• Oftentimes easier to rewrite than to understand
• Unit tests protect components
11
12. Written when…
• Understanding the problem or solution
– Describe what you expect, include edge cases
– Test that you implemented your understanding… for free
– Akin to rubber duck debugging
– By nature, UI work is iterative
• Teamwork
– Encourage reuse: code samples for now or later
– Ease maintenance: pinpoint source of problems
– Team growth or change
• Refactoring
– Enforce the existing API
– Or highlight where it’s broken
12
16. Documentation exposes equally
The good
• Brilliant solution
• Efficient component
• Stable API
• Beautiful design
• You see it,
– You have confidence
And the not so good
• Defect
• Slow component
• Difficult API
• Odd design
• You see it,
– You can improve it
16
19. SOLID is easier to specify/test*
• Single responsible principle
– A component has a single responsibility
• Open/closed principle
– Open for extension, closed for modification
• Liskov substitution principle
– Objects replaceable with instances of their subtypes
• Interface segregation principle
– Client-specific interfaces over general-purpose ones
• Dependency inversion principle
– Depend upon abstractions, not concretions
• * = see separation of concerns
19
20. Transparent
• No silver bullet
• Highlights equally strengths and flaws
– So you can see them
• Testable code is more likely to be SOLID
• Fit it in your coding habits/methodologies
20
30. Unit tests in JavaScript
Jasmine helps us write formal, executable
specifications. It integrates transparently with
our development methodologies while supporting
us with a set of tools.
30