+ All Categories
Home > Software > JavaScript Unit Testing

JavaScript Unit Testing

Date post: 03-Jul-2015
Category:
Upload: shabnamshahfar
View: 618 times
Download: 1 times
Share this document with a friend
Description:
JavaScript Unit Testing
30
Shabnam Shahfar @ShabnamShahfar Prairie Dev Con, 2014 Protegra
Transcript
Page 1: JavaScript Unit Testing

Shabnam Shahfar

@ShabnamShahfar

Prairie Dev Con, 2014Protegra

Page 2: JavaScript Unit Testing

What is a unit test?

Test Driven Development

Running a unit test in a browser

Libraries and Frameworks

Writing Testable JavaScript

Exercise/Demo

2

Page 3: JavaScript Unit Testing

3

Page 4: JavaScript Unit Testing

A test for the smallest testable part of your application

4

Page 5: JavaScript Unit Testing

Isolated and Independent

Repeatable

Small

Easy to read

Fast

5

Page 6: JavaScript Unit Testing

6

Page 7: JavaScript Unit Testing

7

Page 8: JavaScript Unit Testing

Find problems early

Develop & refactor with confidence

Easier than testing manually

Documentation

On-going Regression Testing

Better Design

8

Page 9: JavaScript Unit Testing

“Do the pieces work together as expected?”

Simulate user’s behavior

9

Page 10: JavaScript Unit Testing

They don’t help you write better code, they just make sure your application still works.

Slower than unit testing

10

Page 11: JavaScript Unit Testing

11

Page 12: JavaScript Unit Testing

12

Page 13: JavaScript Unit Testing

Block Scope vs. Function Scope

Proxy Objects

Simulating DOM Events

13

Page 14: JavaScript Unit Testing

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

Page 15: JavaScript Unit Testing

Block Scope vs. Function Scope

Proxy Objects

Simulating DOM Events

15

Page 16: JavaScript Unit Testing

16

Page 17: JavaScript Unit Testing

Block Scope vs. Function Scope

Proxy Objects

Simulating DOM Events

17

Page 18: JavaScript Unit Testing

Example

18

Page 19: JavaScript Unit Testing

Code organization

19

Page 20: JavaScript Unit Testing

20

Page 21: JavaScript Unit Testing

21

Presentation & Interaction

Application State

Data/Server Communication

Setup

Page 22: JavaScript Unit Testing

Anonymous functions, lack of structure

Complex, oversized functions

Hidden or shared state

Tightly coupled

22

Page 23: JavaScript Unit Testing

23

Page 24: JavaScript Unit Testing

24

Page 25: JavaScript Unit Testing

25

Page 26: JavaScript Unit Testing

26

Page 27: JavaScript Unit Testing

Keep methods simple

Don’t intermingle responsibilities

27

Page 28: JavaScript Unit Testing

Write test first!

28

Page 30: JavaScript Unit Testing

30


Recommended