TDD in JavaScript
@bkeepers
@dhavaltrivedi
Ice Cream
Pro
TDD
Refactor
Concerns
Abstractions
Design Patterns
Decouple
Encapsulations
DRY
Why?
Flexible
Maintainable
TDD
Insurance
Philosophy
Design Process
What
before
How
My way
Bad code!
Testing makes
design problems
painfully obvious.
@bkeepers
“The same structure that makes the code difficult to test now will make it difficult to change in the future.”
Steve Freeman, Nat Pryce
Growing Object-Oriented Software Guided by Tests
System Testing
Does not encourage
good design.
System tests tell you your application is
functioning, but tell you nothing about
the internal state.
Unit tests help ensure components are well
designed and function properly.
“To keep unit tests understandable (and, so, maintainable), we have to limit their scope.”
Steve Freeman, Nat Pryce
Growing Object-Oriented Software Guided by Tests
Framework?
We can use unit tests to
improve our design, but first...
Apply Design Patterns
“Each pattern describes a problem that occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice.”
Christopher Alexander
Architect
Design patterns are
the basic parts of speech that
allow us to create coherent,
well-structured systems.
Advantages
Duplication
Shared Vocab
Generic, Reusable
Components
Proven, tested Paradigms
Easier to test
“Patterns don’t solve all design problems, nor do they replace good software designers, however, they do support them."
Addy Osmani
MVC
“The idea behind [MVC] is to make a clear division between domain objects that model our perception of the real world, and presentation objects that are the GUI elements we see on the screen.”
Martin Fowler
Model
domain or structural objects representing
the application’s state
Model
domain or structural objects representing
the application’s state
Controller
translates user input into operations on the model
View
observes the model’s state and
generates output for the user
MVC is just one design
pattern. There are many
others that can help us.
“Writing clean code requires the disciplined use of a myriad of little techniques applied through a painstakingly acquired sense of ‘cleanliness. ”
Single Responsibility
Principle
Every object should have a single responsibility,
and that responsibility should be
entirely encapsulated by the object.
And/or
End.
TDD in JavaScript
By dytrivedi
TDD in JavaScript
- 750