+ All Categories
Home > Documents > TripCase Unit Testing with Jasmine

TripCase Unit Testing with Jasmine

Date post: 16-May-2015
Category:
Upload: stephen-pond
View: 702 times
Download: 2 times
Share this document with a friend
Popular Tags:
32
TripCase Unit Testing with Jasmine Presented by Steve Pond @stephenpond Tuesday, December 11, 12
Transcript
Page 1: TripCase Unit Testing with Jasmine

TripCase Unit Testing with JasminePresented by Steve Pond @stephenpond

Tuesday, December 11, 12

Page 2: TripCase Unit Testing with Jasmine

Overview

What to Unit Test?

Test Driven Development

Walkthrough of Jasmine Unit Testing and Tools

Walkthrough of JSCover - coverage testing

Q & A

Tuesday, December 11, 12

Page 3: TripCase Unit Testing with Jasmine

Unit TestingRepeatable: You can rerun the same test as many times as you want.

Consistent: Every time you run it, you get the same result. (for example: Using threads can produce an inconsistent result)

In Memory: It has no “hard” dependencies on anything not in memory (such as file system, databases, network)

Fast: It should take less than half a second to run a unit test.

Checking one single concern or “use case” in the system: (More than one can make it harder to understand what or where the problem is when the problem arises.)

Tuesday, December 11, 12

Page 4: TripCase Unit Testing with Jasmine

Integration TestingUse system dependent values that change dynamically (such as DateTime.Now, or Environment.MachineName)

Create objects of which it has little control (such as threads, random number generators)

Reach out to external systems or local machine dependencies (from calling web services to using local configuration files)

Test multiple things in the course of one test case (from database integrity, to configurations, to protocols, to system logic, in one go).

Tuesday, December 11, 12

Page 5: TripCase Unit Testing with Jasmine

What to Unit Test?

Tuesday, December 11, 12

Page 6: TripCase Unit Testing with Jasmine

Framework implements multiple libraries

Inner-team dialogues are generally integration related

Deadline Driven. Zero time.

GreenField - BrownField

TripCase UT Barriers

Tuesday, December 11, 12

Page 7: TripCase Unit Testing with Jasmine

ProcedureDetermining what is unit-testable

Tuesday, December 11, 12

Page 8: TripCase Unit Testing with Jasmine

ReflexiveDoes its own thing... (extension to our app’s core logic)

Tuesday, December 11, 12

Page 9: TripCase Unit Testing with Jasmine

AlgorithmicOur apps consciousness, makes decisions, etc...

Tuesday, December 11, 12

Page 10: TripCase Unit Testing with Jasmine

TripCase Analysis

Core

Router

Views

Controller

Workflows

Model/Collection

Tuesday, December 11, 12

Page 11: TripCase Unit Testing with Jasmine

Core

Heartbeat

Sets up Require config

app.js

Initializes app modules

Tuesday, December 11, 12

Page 12: TripCase Unit Testing with Jasmine

Core - Reflexive

Mainly just initialization

Launching the App

Tuesday, December 11, 12

Page 13: TripCase Unit Testing with Jasmine

Router

History Stack

Navigation API

Map hash change to mediator events & vice versa

Tuesday, December 11, 12

Page 14: TripCase Unit Testing with Jasmine

Router - Reflexive

Mainly just mapping hash changes to mediator events

API, and history stack, handed to us

Tuesday, December 11, 12

Page 15: TripCase Unit Testing with Jasmine

Views

Views present model data and respond to client interactions

Ideally, views just render and invoke actions on the model

Tuesday, December 11, 12

Page 16: TripCase Unit Testing with Jasmine

Views - Reflexive

Views merely couple the model and the client interaction

Up for debate: some success/fail scenarios sometimes handled in view? Sounds Algorithmic.

Use discretion on Unit Testing

Tuesday, December 11, 12

Page 17: TripCase Unit Testing with Jasmine

Controllers

Module/Feature level, initializes the workflow or view

Workflow handles app state change, swaps views

Controller listens to mediator events for various action

Listens to view/workflow level events

Tuesday, December 11, 12

Page 18: TripCase Unit Testing with Jasmine

Controller - Reflexive

Workflows should be kept lean (refer to SOLID principle) and stick to single responsibility rule

Controllers mainly just mapping the mediator to workflow or view initializations

In practice, I have seen a lot of app logic handled in workflows. Unit Test with discretion.

Tuesday, December 11, 12

Page 19: TripCase Unit Testing with Jasmine

Models

Sync, fetch, and Save

Special parsing

Special validation

Special helpers

Special URL and payload

Tuesday, December 11, 12

Page 20: TripCase Unit Testing with Jasmine

Models - Algorithmic

Models/ Collections - clear choice for unit test candidates

We provide a lot of logic for parsing and helpers here

Tuesday, December 11, 12

Page 21: TripCase Unit Testing with Jasmine

Next Step: Draft our spec

Analyze a story

Pseudo Code

Tuesday, December 11, 12

Page 22: TripCase Unit Testing with Jasmine

Analyze Story: Share Itinerary

Contacts Collection

Share contacts helper should return all contacts that are shared

Contacts model

Should properly construct a URL for syncing

Should properly construct a payload for fetching

Should properly construct a payload for saving

Should properly validate user Input

Should properly set attributes for a given response

Tuesday, December 11, 12

Page 23: TripCase Unit Testing with Jasmine

Test-Driven Development

Tuesday, December 11, 12

Page 24: TripCase Unit Testing with Jasmine

Ken Beckwho is credited with having developed or 'rediscovered' the technique, stated in

TDD encourages simple designs and inspires

confidence.

Tuesday, December 11, 12

Page 25: TripCase Unit Testing with Jasmine

A Simple TDD Workflow 1.Write test stubs based on business requirements for a new feature 2.Write minimal code in Spec to PASS the unit test 3.Tweak code to pass the FUNCTIONAL test 4.Go back and tweak the unit test with new code and Together until SUCCESS

Tuesday, December 11, 12

Page 26: TripCase Unit Testing with Jasmine

Group Activity: Analyze a Story

Given the story of a Search Hotel Module, identify the unit-testable assertions

Apply it to a minimal Jasmine Spec Template

Tuesday, December 11, 12

Page 27: TripCase Unit Testing with Jasmine

Jasmine Basics

Tuesday, December 11, 12

Page 28: TripCase Unit Testing with Jasmine

Jasmine Basics - Blocks

Tuesday, December 11, 12

Page 29: TripCase Unit Testing with Jasmine

Jasmine Basics - Setup/Teardown

Tuesday, December 11, 12

Page 30: TripCase Unit Testing with Jasmine

Jasmine Basics - Spies

Tuesday, December 11, 12

Page 31: TripCase Unit Testing with Jasmine

Jasmine Basics - Sinon(not really unit-testing, but useful for integration testing)

Tuesday, December 11, 12

Page 32: TripCase Unit Testing with Jasmine

Walkthrough

Tuesday, December 11, 12


Recommended