Date post: | 03-Jul-2015 |
Category: |
Software |
Upload: | shabnamshahfar |
View: | 618 times |
Download: | 1 times |
Shabnam Shahfar
@ShabnamShahfar
Prairie Dev Con, 2014Protegra
What is a unit test?
Test Driven Development
Running a unit test in a browser
Libraries and Frameworks
Writing Testable JavaScript
Exercise/Demo
2
3
A test for the smallest testable part of your application
4
Isolated and Independent
Repeatable
Small
Easy to read
Fast
5
6
7
Find problems early
Develop & refactor with confidence
Easier than testing manually
Documentation
On-going Regression Testing
Better Design
8
“Do the pieces work together as expected?”
Simulate user’s behavior
9
They don’t help you write better code, they just make sure your application still works.
Slower than unit testing
10
11
12
Block Scope vs. Function Scope
Proxy Objects
Simulating DOM Events
13
Function scope also means that variables declared inside functions are only available inside those functions, once the function exits, the variables are inaccessible.
JavaScript does have private variables. You declare them inside closures.
14
Block Scope vs. Function Scope
Proxy Objects
Simulating DOM Events
15
16
Block Scope vs. Function Scope
Proxy Objects
Simulating DOM Events
17
Example
18
Code organization
19
20
21
Presentation & Interaction
Application State
Data/Server Communication
Setup
Anonymous functions, lack of structure
Complex, oversized functions
Hidden or shared state
Tightly coupled
22
23
24
25
26
Keep methods simple
Don’t intermingle responsibilities
27
Write test first!
28
Books:
JavaScript the good parts, by Douglas Crockford
JavaScript unit testing, by Hazem Saleh
http://alistapart.com/article/writing-testable-javascript
http://www.adequatelygood.com/Writing-Testable-JavaScript.html
29
30