SlideShare a Scribd company logo
1 of 60
Zero to Testing in
JavaScript
Basics of testing, in JS
About me
• Blog: thewebivore.com
• Twitter: @pamasaur
• Co-organizer of Philadelphia JavaScript Developers
• Podcasting on Turing Incomplete (@turingcool)
• Testing fanatic
@pamasaur | #midwestjs | thewebivore.com
@pamasaur | #midwestjs | thewebivore.com
Welcome to the testing track?
@pamasaur | #midwestjs | thewebivore.com
*pause* … A TESTING TRACK!
@pamasaur | #midwestjs | thewebivore.com
Let’s kick this off right!
Agenda
• My testing story
• Testing theory
• Basic test walk-through
• Testing frameworks
• Other forms of testing
• Working testing into your workflow
• Minishop (workshop)
@pamasaur | #midwestjs | thewebivore.com
My testing story
When I first started writing tests
Code Retreat
• TDD
• Pairing
• Throw-away code
@pamasaur | #midwestjs | thewebivore.com
@pamasaur | #midwestjs | thewebivore.com
What about tests in my projects?
@pamasaur | #midwestjs | thewebivore.com
previously:
“Tests* are doing the dishes”
* and writing docs and fixing bad code
@pamasaur | #midwestjs | thewebivore.com
aka:
“Tests are work for people you don’t like”
@pamasaur | #midwestjs | thewebivore.com
The other piece that I would add to this is, and I’ve said
this before at talks, that testing isn’t something that you do
because it is good to be testing. It’s not your lettuce.
You do it because it increases your confidence in your
code. And it increases your ability to release quickly and
make changes without worrying that something is going to
break. And so, if you’re paranoid like me, that’s a good
incentive to do testing. And if you have a whole lot of self-
confidence, maybe you’re just a really great coder. But
maybe it’s a little bit more likely that you’re
going to make mistakes and you might pay for it
a little bit later.
Julie Ralph, Protractor
http://javascriptjabber.com/106-jsj-protractor-with-julie-ralph/
@pamasaur | #midwestjs | thewebivore.com
@pamasaur | #midwestjs | thewebivore.com
now:
GOOD developers write tests
@pamasaur | #midwestjs | thewebivore.com
Literally.
@pamasaur | #midwestjs | thewebivore.com
-b for bad coder
What do you call code without tests?
Legacy code.
@pamasaur | #midwestjs | thewebivore.com
Testing basics
1. When you break it, it breaks!
2. Secondary line of documentation defense
3. Design tool
@pamasaur | #midwestjs | thewebivore.com
When you break it, it breaks!
• Testing is required to enable refactoring
• Regularly run tests
• Use test results to make decisions
@pamasaur | #midwestjs | thewebivore.com
Documentation defense
• Tests describe behavior
• Read tests to understand behavior
• Write tests to describe behavior
• Write tests to validate behavior
@pamasaur | #midwestjs | thewebivore.com
Tests as design tool
• Tests describe functionality
• Write functionality description (test)
• Write code to make it work
@pamasaur | #midwestjs | thewebivore.com
BDD/TDD
• Behavior Driven Development
• Test-Driven Development
“Write tests to inform how you write your code”
@pamasaur | #midwestjs | thewebivore.com
BDD
• describe
• it
• before
• after
• beforeEach
• afterEach
@pamasaur | #midwestjs | thewebivore.com
TDD
• suite
• test
• setup
• teardown
@pamasaur | #midwestjs | thewebivore.com
Test Ever vs. Test Never
@pamasaur | #midwestjs | thewebivore.com
Types of testing
• Unit
• Integration
• Functional
• E2E
@pamasaur | #midwestjs | thewebivore.com
Unit
Testing functionality in isolation
“When I call addNumbers, it returns the value of the added
numbers”
@pamasaur | #midwestjs | thewebivore.com
Unit testing takeaway:
Test your code
@pamasaur | #midwestjs | thewebivore.com
How to only test your code?
• Isolate
• Faking
@pamasaur | #midwestjs | thewebivore.com
Fake things: Spies, stubs, and mocks
• Spy: an object that records its interactions
• Stubs: fake objects
• Mocks: fake objects with expected behavior
Generally, you can SPY on a function, STUB an
object, and MOCK a service.
@pamasaur | #midwestjs | thewebivore.com
Integration
• Multiple pieces of code together
“Is the router setting up my models correctly?”
@pamasaur | #midwestjs | thewebivore.com
Functional
• Does your code work as product expects it to? (functional
requirements)
“When I click the login button, it should log me in”
@pamasaur | #midwestjs | thewebivore.com
E2E (end-to-end)
• Functional, but fully integrated with external services, simulate
real-time situations.
“When I click ‘Login with Google,’ it logs me in”
@pamasaur | #midwestjs | thewebivore.com
JavaScript test walk-through
JavaScript test walk-through
• Setting up your base
• Writing the test/expectations*
• Making it pass*
* The order of these is debatable
@pamasaur | #midwestjs | thewebivore.com
Jasmine
• jasmine.github.io
• Download a standalone version on GitHub from pivotal/jasmine
• Node: jasmine-node (fork of karma-jasmine)
@pamasaur | #midwestjs | thewebivore.com
Mocha
• visionmedia.github.io/mocha
• Node!
• npm install –g mocha
@pamasaur | #midwestjs | thewebivore.com
Anatomy of a test
Describe [thing you’re testing]
It [does something you expect it to do]
Rinse and repeat.
@pamasaur | #midwestjs | thewebivore.com
Example test walk-through
with Mocha
var assert = require('assert');
describe("An area of my application", function() {
it("should know that 2 and 2 is 4", function(){
assert.equal(4, 2+2);
});
});
@pamasaur | #midwestjs | thewebivore.com
describe("An area of my application", function() {
it("should know that 2 and 2 is 4", function(){
assert.equal(4, 2+2);
});
});
@pamasaur | #midwestjs | thewebivore.com
var assert = require('assert');
describe( , function() {
it("should know that 2 and 2 is 4", function(){
assert.equal(4, 2+2);
});
});
@pamasaur | #midwestjs | thewebivore.com
var assert = require('assert');
describe("An area of my application", {
it("should know that 2 and 2 is 4", {
assert.equal(4, 2+2);
});
});
@pamasaur | #midwestjs | thewebivore.com
var assert = require('assert');
describe("An area of my application", function() {
it( , function(){
});
});
@pamasaur | #midwestjs | thewebivore.com
@pamasaur | #midwestjs | thewebivore.com
Testing Tools
Test describers
• Jasmine
• Mocha
• QUnit
• node-tap
• YUI Test
@pamasaur | #midwestjs | thewebivore.com
Assertions
• Chai
• should.js
• Expect.js
• better-assert
@pamasaur | #midwestjs | thewebivore.com
Spies, stubs, and mocks
• Sinon.js
• Jest from Facebook
@pamasaur | #midwestjs | thewebivore.com
Test runners
• Karma
• Testem
• YUI Yeti
@pamasaur | #midwestjs | thewebivore.com
Bringing testing into the fold
3 tips for making testing a regular part of your world
#1: Teach testing
• Attend talks like this!
• Practice (ex. Code Retreat)
• Pair programming
@pamasaur | #midwestjs | thewebivore.com
#2: Code coverage
• Istanbul
• Blanket.js
@pamasaur | #midwestjs | thewebivore.com
#3: Code review
• Quality assurance
• Mentoring
• Don’t accept without tests!
@pamasaur | #midwestjs | thewebivore.com
What’d we learn?
• Basics of testing
• Writing a JavaScript test
• Tools in JavaScript for testing
• Ways to create a testing culture
@pamasaur | #midwestjs | thewebivore.com
Minishop
(workshop, playshop …)
TODO
• Set up karma (our test runner)
• With Jasmine (our assertion framework)
@pamasaur | #midwestjs | thewebivore.com
TODO
• Write a failing test
• Correct the failing test
@pamasaur | #midwestjs | thewebivore.com
TODO
• Write another test
• Setup in beforeEach
@pamasaur | #midwestjs | thewebivore.com
Thank you!
• Find me online at
• @pamasaur
• thewebivore.com (blog)
• turing.cool (podcast)
• thewebivore.com/book (book!)
@pamasaur | #midwestjs | thewebivore.com

More Related Content

What's hot

Introduction to testing in Rails
Introduction to testing in RailsIntroduction to testing in Rails
Introduction to testing in Railsbenlcollins
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!Ortus Solutions, Corp
 
Introduction To Web Application Testing
Introduction To Web Application TestingIntroduction To Web Application Testing
Introduction To Web Application TestingYnon Perek
 
Angularjs - Unit testing introduction
Angularjs - Unit testing introductionAngularjs - Unit testing introduction
Angularjs - Unit testing introductionNir Kaufman
 
Intro to testing Javascript with jasmine
Intro to testing Javascript with jasmineIntro to testing Javascript with jasmine
Intro to testing Javascript with jasmineTimothy Oxley
 
Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101Roy Yu
 
Djangocon 2014 angular + django
Djangocon 2014 angular + djangoDjangocon 2014 angular + django
Djangocon 2014 angular + djangoNina Zakharenko
 
Lunch and learn: Cucumber and Capybara
Lunch and learn: Cucumber and CapybaraLunch and learn: Cucumber and Capybara
Lunch and learn: Cucumber and CapybaraMarc Seeger
 
RSpec on Rails Tutorial
RSpec on Rails TutorialRSpec on Rails Tutorial
RSpec on Rails TutorialWen-Tien Chang
 
Writing Software not Code with Cucumber
Writing Software not Code with CucumberWriting Software not Code with Cucumber
Writing Software not Code with CucumberBen Mabey
 
Unit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma introUnit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma introMaurice De Beijer [MVP]
 
Getting Answers to Your Testing Questions
Getting Answers to Your Testing QuestionsGetting Answers to Your Testing Questions
Getting Answers to Your Testing Questionsjasnow
 
Efficient Rails Test Driven Development (class 3) by Wolfram Arnold
Efficient Rails Test Driven Development (class 3) by Wolfram ArnoldEfficient Rails Test Driven Development (class 3) by Wolfram Arnold
Efficient Rails Test Driven Development (class 3) by Wolfram ArnoldMarakana Inc.
 
Efficient Rails Test Driven Development (class 4) by Wolfram Arnold
Efficient Rails Test Driven Development (class 4) by Wolfram ArnoldEfficient Rails Test Driven Development (class 4) by Wolfram Arnold
Efficient Rails Test Driven Development (class 4) by Wolfram ArnoldMarakana Inc.
 
Refactoring Away from Test Hell
Refactoring Away from Test HellRefactoring Away from Test Hell
Refactoring Away from Test HellAlastair Smith
 
Django REST Framework
Django REST FrameworkDjango REST Framework
Django REST FrameworkLoad Impact
 
Objective C 基本介紹
Objective C 基本介紹Objective C 基本介紹
Objective C 基本介紹Giga Cheng
 
Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6Marakana Inc.
 

What's hot (20)

Introduction to testing in Rails
Introduction to testing in RailsIntroduction to testing in Rails
Introduction to testing in Rails
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!
 
Introduction To Web Application Testing
Introduction To Web Application TestingIntroduction To Web Application Testing
Introduction To Web Application Testing
 
Angularjs - Unit testing introduction
Angularjs - Unit testing introductionAngularjs - Unit testing introduction
Angularjs - Unit testing introduction
 
Intro to testing Javascript with jasmine
Intro to testing Javascript with jasmineIntro to testing Javascript with jasmine
Intro to testing Javascript with jasmine
 
Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101
 
Djangocon 2014 angular + django
Djangocon 2014 angular + djangoDjangocon 2014 angular + django
Djangocon 2014 angular + django
 
Lunch and learn: Cucumber and Capybara
Lunch and learn: Cucumber and CapybaraLunch and learn: Cucumber and Capybara
Lunch and learn: Cucumber and Capybara
 
RSpec on Rails Tutorial
RSpec on Rails TutorialRSpec on Rails Tutorial
RSpec on Rails Tutorial
 
Writing Software not Code with Cucumber
Writing Software not Code with CucumberWriting Software not Code with Cucumber
Writing Software not Code with Cucumber
 
Unit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma introUnit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma intro
 
Getting Answers to Your Testing Questions
Getting Answers to Your Testing QuestionsGetting Answers to Your Testing Questions
Getting Answers to Your Testing Questions
 
Efficient Rails Test Driven Development (class 3) by Wolfram Arnold
Efficient Rails Test Driven Development (class 3) by Wolfram ArnoldEfficient Rails Test Driven Development (class 3) by Wolfram Arnold
Efficient Rails Test Driven Development (class 3) by Wolfram Arnold
 
Efficient Rails Test Driven Development (class 4) by Wolfram Arnold
Efficient Rails Test Driven Development (class 4) by Wolfram ArnoldEfficient Rails Test Driven Development (class 4) by Wolfram Arnold
Efficient Rails Test Driven Development (class 4) by Wolfram Arnold
 
Refactoring Away from Test Hell
Refactoring Away from Test HellRefactoring Away from Test Hell
Refactoring Away from Test Hell
 
Selenium bootcamp slides
Selenium bootcamp slides   Selenium bootcamp slides
Selenium bootcamp slides
 
Django REST Framework
Django REST FrameworkDjango REST Framework
Django REST Framework
 
Objective C 基本介紹
Objective C 基本介紹Objective C 基本介紹
Objective C 基本介紹
 
DDD with Behat
DDD with BehatDDD with Behat
DDD with Behat
 
Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6Efficient Rails Test-Driven Development - Week 6
Efficient Rails Test-Driven Development - Week 6
 

Viewers also liked

Displacing Worst Practices in CSS
Displacing Worst Practices in CSSDisplacing Worst Practices in CSS
Displacing Worst Practices in CSSpamselle
 
Simple Proxying in Rails
Simple Proxying in RailsSimple Proxying in Rails
Simple Proxying in Railspamselle
 
Selecting a Web Framework
Selecting a Web FrameworkSelecting a Web Framework
Selecting a Web Frameworkpamselle
 
Feminism & Open Source Contribution
Feminism & Open Source ContributionFeminism & Open Source Contribution
Feminism & Open Source Contributionpamselle
 
WordPress 101 Sunday Session
WordPress 101 Sunday SessionWordPress 101 Sunday Session
WordPress 101 Sunday Sessionpamselle
 
Sadia Afroz: Detecting Hoaxes, Frauds, and Deception in Writing Style Online
Sadia Afroz: Detecting Hoaxes, Frauds, and Deception in Writing Style Online  Sadia Afroz: Detecting Hoaxes, Frauds, and Deception in Writing Style Online
Sadia Afroz: Detecting Hoaxes, Frauds, and Deception in Writing Style Online pamselle
 

Viewers also liked (6)

Displacing Worst Practices in CSS
Displacing Worst Practices in CSSDisplacing Worst Practices in CSS
Displacing Worst Practices in CSS
 
Simple Proxying in Rails
Simple Proxying in RailsSimple Proxying in Rails
Simple Proxying in Rails
 
Selecting a Web Framework
Selecting a Web FrameworkSelecting a Web Framework
Selecting a Web Framework
 
Feminism & Open Source Contribution
Feminism & Open Source ContributionFeminism & Open Source Contribution
Feminism & Open Source Contribution
 
WordPress 101 Sunday Session
WordPress 101 Sunday SessionWordPress 101 Sunday Session
WordPress 101 Sunday Session
 
Sadia Afroz: Detecting Hoaxes, Frauds, and Deception in Writing Style Online
Sadia Afroz: Detecting Hoaxes, Frauds, and Deception in Writing Style Online  Sadia Afroz: Detecting Hoaxes, Frauds, and Deception in Writing Style Online
Sadia Afroz: Detecting Hoaxes, Frauds, and Deception in Writing Style Online
 

Similar to MidwestJS Zero to Testing

Apex Testing Deep Dive
Apex Testing Deep DiveApex Testing Deep Dive
Apex Testing Deep DiveAdam Olshansky
 
Node.js Development Workflow Automation with Grunt.js
Node.js Development Workflow Automation with Grunt.jsNode.js Development Workflow Automation with Grunt.js
Node.js Development Workflow Automation with Grunt.jskiyanwang
 
The Cowardly Test-o-Phobe's Guide To Testing
The Cowardly Test-o-Phobe's Guide To TestingThe Cowardly Test-o-Phobe's Guide To Testing
The Cowardly Test-o-Phobe's Guide To TestingTim Duckett
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWHolger Grosse-Plankermann
 
Data Driven DevOps
Data Driven DevOpsData Driven DevOps
Data Driven DevOpsLeon Stigter
 
Anatomy of Test Driven Development
Anatomy of Test Driven DevelopmentAnatomy of Test Driven Development
Anatomy of Test Driven DevelopmentDhaval Shah
 
The what, why and how of web analytics testing
The what, why and how of web analytics testingThe what, why and how of web analytics testing
The what, why and how of web analytics testingAnand Bagmar
 
Browser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsBrowser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsLuís Bastião Silva
 
How to not blow up spaceships
How to not blow up spaceshipsHow to not blow up spaceships
How to not blow up spaceshipsSabin Marcu
 
Just Mock It - Mocks and Stubs
Just Mock It - Mocks and StubsJust Mock It - Mocks and Stubs
Just Mock It - Mocks and StubsGavin Pickin
 
Devday2016 real unittestingwithmockframework-phatvu
Devday2016 real unittestingwithmockframework-phatvuDevday2016 real unittestingwithmockframework-phatvu
Devday2016 real unittestingwithmockframework-phatvuPhat VU
 
My Little Webap - DevOpsSec is Magic
My Little Webap - DevOpsSec is MagicMy Little Webap - DevOpsSec is Magic
My Little Webap - DevOpsSec is MagicApollo Clark
 
The Many Ways to Test Your React App
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React AppAll Things Open
 
Measuring Coverage From E2E Tests
Measuring Coverage From E2E TestsMeasuring Coverage From E2E Tests
Measuring Coverage From E2E TestsAnand Bagmar
 
Data driven devops as presented at QCon London 2018
Data driven devops as presented at QCon London 2018Data driven devops as presented at QCon London 2018
Data driven devops as presented at QCon London 2018Baruch Sadogursky
 
Selenium Tips & Tricks - StarWest 2015
Selenium Tips & Tricks - StarWest 2015Selenium Tips & Tricks - StarWest 2015
Selenium Tips & Tricks - StarWest 2015Andrew Krug
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testingSteven Casey
 
A Deep Dive Into SEO Tactics For Modern Javascript Frameworks
A Deep Dive Into SEO Tactics For Modern Javascript FrameworksA Deep Dive Into SEO Tactics For Modern Javascript Frameworks
A Deep Dive Into SEO Tactics For Modern Javascript FrameworksHamlet Batista
 

Similar to MidwestJS Zero to Testing (20)

Apex Testing Deep Dive
Apex Testing Deep DiveApex Testing Deep Dive
Apex Testing Deep Dive
 
Node.js Development Workflow Automation with Grunt.js
Node.js Development Workflow Automation with Grunt.jsNode.js Development Workflow Automation with Grunt.js
Node.js Development Workflow Automation with Grunt.js
 
The Cowardly Test-o-Phobe's Guide To Testing
The Cowardly Test-o-Phobe's Guide To TestingThe Cowardly Test-o-Phobe's Guide To Testing
The Cowardly Test-o-Phobe's Guide To Testing
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRW
 
Data Driven DevOps
Data Driven DevOpsData Driven DevOps
Data Driven DevOps
 
Foundation selenium java
Foundation selenium java Foundation selenium java
Foundation selenium java
 
Anatomy of Test Driven Development
Anatomy of Test Driven DevelopmentAnatomy of Test Driven Development
Anatomy of Test Driven Development
 
The what, why and how of web analytics testing
The what, why and how of web analytics testingThe what, why and how of web analytics testing
The what, why and how of web analytics testing
 
Browser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsBrowser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.js
 
How to not blow up spaceships
How to not blow up spaceshipsHow to not blow up spaceships
How to not blow up spaceships
 
Just Mock It - Mocks and Stubs
Just Mock It - Mocks and StubsJust Mock It - Mocks and Stubs
Just Mock It - Mocks and Stubs
 
Devday2016 real unittestingwithmockframework-phatvu
Devday2016 real unittestingwithmockframework-phatvuDevday2016 real unittestingwithmockframework-phatvu
Devday2016 real unittestingwithmockframework-phatvu
 
My Little Webap - DevOpsSec is Magic
My Little Webap - DevOpsSec is MagicMy Little Webap - DevOpsSec is Magic
My Little Webap - DevOpsSec is Magic
 
The Many Ways to Test Your React App
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React App
 
Away day
Away dayAway day
Away day
 
Measuring Coverage From E2E Tests
Measuring Coverage From E2E TestsMeasuring Coverage From E2E Tests
Measuring Coverage From E2E Tests
 
Data driven devops as presented at QCon London 2018
Data driven devops as presented at QCon London 2018Data driven devops as presented at QCon London 2018
Data driven devops as presented at QCon London 2018
 
Selenium Tips & Tricks - StarWest 2015
Selenium Tips & Tricks - StarWest 2015Selenium Tips & Tricks - StarWest 2015
Selenium Tips & Tricks - StarWest 2015
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testing
 
A Deep Dive Into SEO Tactics For Modern Javascript Frameworks
A Deep Dive Into SEO Tactics For Modern Javascript FrameworksA Deep Dive Into SEO Tactics For Modern Javascript Frameworks
A Deep Dive Into SEO Tactics For Modern Javascript Frameworks
 

More from pamselle

WordPress 101 Saturday Session
WordPress 101 Saturday SessionWordPress 101 Saturday Session
WordPress 101 Saturday Sessionpamselle
 
Power Spriting With Compass
Power Spriting With CompassPower Spriting With Compass
Power Spriting With Compasspamselle
 
Aylin Caliskan: Quantifying the Translator Effect: Identifying authors and ma...
Aylin Caliskan: Quantifying the Translator Effect: Identifying authors and ma...Aylin Caliskan: Quantifying the Translator Effect: Identifying authors and ma...
Aylin Caliskan: Quantifying the Translator Effect: Identifying authors and ma...pamselle
 
Kamelia Aryafar: Musical Genre Classification Using Sparsity-Eager Support Ve...
Kamelia Aryafar: Musical Genre Classification Using Sparsity-Eager Support Ve...Kamelia Aryafar: Musical Genre Classification Using Sparsity-Eager Support Ve...
Kamelia Aryafar: Musical Genre Classification Using Sparsity-Eager Support Ve...pamselle
 
GDI WordPress 4 January 2012 (white)
GDI WordPress 4 January 2012 (white)GDI WordPress 4 January 2012 (white)
GDI WordPress 4 January 2012 (white)pamselle
 
GDI WordPress 4 January 2012
GDI WordPress 4 January 2012GDI WordPress 4 January 2012
GDI WordPress 4 January 2012pamselle
 
GDI WordPress 3 January 2012 (white background)
GDI WordPress 3 January 2012 (white background)GDI WordPress 3 January 2012 (white background)
GDI WordPress 3 January 2012 (white background)pamselle
 
GDI WordPress 3 January 2012
GDI WordPress 3 January 2012GDI WordPress 3 January 2012
GDI WordPress 3 January 2012pamselle
 
GDI WordPress 2 January 2012
GDI WordPress 2 January 2012 GDI WordPress 2 January 2012
GDI WordPress 2 January 2012 pamselle
 
Gdi word press_2
Gdi word press_2Gdi word press_2
Gdi word press_2pamselle
 
GDI WordPress 1 January 2012
GDI WordPress 1 January 2012GDI WordPress 1 January 2012
GDI WordPress 1 January 2012pamselle
 

More from pamselle (11)

WordPress 101 Saturday Session
WordPress 101 Saturday SessionWordPress 101 Saturday Session
WordPress 101 Saturday Session
 
Power Spriting With Compass
Power Spriting With CompassPower Spriting With Compass
Power Spriting With Compass
 
Aylin Caliskan: Quantifying the Translator Effect: Identifying authors and ma...
Aylin Caliskan: Quantifying the Translator Effect: Identifying authors and ma...Aylin Caliskan: Quantifying the Translator Effect: Identifying authors and ma...
Aylin Caliskan: Quantifying the Translator Effect: Identifying authors and ma...
 
Kamelia Aryafar: Musical Genre Classification Using Sparsity-Eager Support Ve...
Kamelia Aryafar: Musical Genre Classification Using Sparsity-Eager Support Ve...Kamelia Aryafar: Musical Genre Classification Using Sparsity-Eager Support Ve...
Kamelia Aryafar: Musical Genre Classification Using Sparsity-Eager Support Ve...
 
GDI WordPress 4 January 2012 (white)
GDI WordPress 4 January 2012 (white)GDI WordPress 4 January 2012 (white)
GDI WordPress 4 January 2012 (white)
 
GDI WordPress 4 January 2012
GDI WordPress 4 January 2012GDI WordPress 4 January 2012
GDI WordPress 4 January 2012
 
GDI WordPress 3 January 2012 (white background)
GDI WordPress 3 January 2012 (white background)GDI WordPress 3 January 2012 (white background)
GDI WordPress 3 January 2012 (white background)
 
GDI WordPress 3 January 2012
GDI WordPress 3 January 2012GDI WordPress 3 January 2012
GDI WordPress 3 January 2012
 
GDI WordPress 2 January 2012
GDI WordPress 2 January 2012 GDI WordPress 2 January 2012
GDI WordPress 2 January 2012
 
Gdi word press_2
Gdi word press_2Gdi word press_2
Gdi word press_2
 
GDI WordPress 1 January 2012
GDI WordPress 1 January 2012GDI WordPress 1 January 2012
GDI WordPress 1 January 2012
 

Recently uploaded

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Recently uploaded (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

MidwestJS Zero to Testing

  • 1. Zero to Testing in JavaScript Basics of testing, in JS
  • 2. About me • Blog: thewebivore.com • Twitter: @pamasaur • Co-organizer of Philadelphia JavaScript Developers • Podcasting on Turing Incomplete (@turingcool) • Testing fanatic @pamasaur | #midwestjs | thewebivore.com
  • 3. @pamasaur | #midwestjs | thewebivore.com Welcome to the testing track?
  • 4. @pamasaur | #midwestjs | thewebivore.com *pause* … A TESTING TRACK!
  • 5. @pamasaur | #midwestjs | thewebivore.com Let’s kick this off right!
  • 6. Agenda • My testing story • Testing theory • Basic test walk-through • Testing frameworks • Other forms of testing • Working testing into your workflow • Minishop (workshop) @pamasaur | #midwestjs | thewebivore.com
  • 8. When I first started writing tests Code Retreat • TDD • Pairing • Throw-away code @pamasaur | #midwestjs | thewebivore.com
  • 9. @pamasaur | #midwestjs | thewebivore.com What about tests in my projects?
  • 10. @pamasaur | #midwestjs | thewebivore.com previously: “Tests* are doing the dishes” * and writing docs and fixing bad code
  • 11. @pamasaur | #midwestjs | thewebivore.com aka: “Tests are work for people you don’t like”
  • 12. @pamasaur | #midwestjs | thewebivore.com The other piece that I would add to this is, and I’ve said this before at talks, that testing isn’t something that you do because it is good to be testing. It’s not your lettuce. You do it because it increases your confidence in your code. And it increases your ability to release quickly and make changes without worrying that something is going to break. And so, if you’re paranoid like me, that’s a good incentive to do testing. And if you have a whole lot of self- confidence, maybe you’re just a really great coder. But maybe it’s a little bit more likely that you’re going to make mistakes and you might pay for it a little bit later. Julie Ralph, Protractor http://javascriptjabber.com/106-jsj-protractor-with-julie-ralph/
  • 13. @pamasaur | #midwestjs | thewebivore.com
  • 14. @pamasaur | #midwestjs | thewebivore.com now: GOOD developers write tests
  • 15. @pamasaur | #midwestjs | thewebivore.com Literally.
  • 16. @pamasaur | #midwestjs | thewebivore.com -b for bad coder
  • 17. What do you call code without tests? Legacy code. @pamasaur | #midwestjs | thewebivore.com
  • 18. Testing basics 1. When you break it, it breaks! 2. Secondary line of documentation defense 3. Design tool @pamasaur | #midwestjs | thewebivore.com
  • 19. When you break it, it breaks! • Testing is required to enable refactoring • Regularly run tests • Use test results to make decisions @pamasaur | #midwestjs | thewebivore.com
  • 20. Documentation defense • Tests describe behavior • Read tests to understand behavior • Write tests to describe behavior • Write tests to validate behavior @pamasaur | #midwestjs | thewebivore.com
  • 21. Tests as design tool • Tests describe functionality • Write functionality description (test) • Write code to make it work @pamasaur | #midwestjs | thewebivore.com
  • 22. BDD/TDD • Behavior Driven Development • Test-Driven Development “Write tests to inform how you write your code” @pamasaur | #midwestjs | thewebivore.com
  • 23. BDD • describe • it • before • after • beforeEach • afterEach @pamasaur | #midwestjs | thewebivore.com
  • 24. TDD • suite • test • setup • teardown @pamasaur | #midwestjs | thewebivore.com
  • 25. Test Ever vs. Test Never @pamasaur | #midwestjs | thewebivore.com
  • 26. Types of testing • Unit • Integration • Functional • E2E @pamasaur | #midwestjs | thewebivore.com
  • 27. Unit Testing functionality in isolation “When I call addNumbers, it returns the value of the added numbers” @pamasaur | #midwestjs | thewebivore.com
  • 28. Unit testing takeaway: Test your code @pamasaur | #midwestjs | thewebivore.com
  • 29. How to only test your code? • Isolate • Faking @pamasaur | #midwestjs | thewebivore.com
  • 30. Fake things: Spies, stubs, and mocks • Spy: an object that records its interactions • Stubs: fake objects • Mocks: fake objects with expected behavior Generally, you can SPY on a function, STUB an object, and MOCK a service. @pamasaur | #midwestjs | thewebivore.com
  • 31. Integration • Multiple pieces of code together “Is the router setting up my models correctly?” @pamasaur | #midwestjs | thewebivore.com
  • 32. Functional • Does your code work as product expects it to? (functional requirements) “When I click the login button, it should log me in” @pamasaur | #midwestjs | thewebivore.com
  • 33. E2E (end-to-end) • Functional, but fully integrated with external services, simulate real-time situations. “When I click ‘Login with Google,’ it logs me in” @pamasaur | #midwestjs | thewebivore.com
  • 35. JavaScript test walk-through • Setting up your base • Writing the test/expectations* • Making it pass* * The order of these is debatable @pamasaur | #midwestjs | thewebivore.com
  • 36. Jasmine • jasmine.github.io • Download a standalone version on GitHub from pivotal/jasmine • Node: jasmine-node (fork of karma-jasmine) @pamasaur | #midwestjs | thewebivore.com
  • 37. Mocha • visionmedia.github.io/mocha • Node! • npm install –g mocha @pamasaur | #midwestjs | thewebivore.com
  • 38. Anatomy of a test Describe [thing you’re testing] It [does something you expect it to do] Rinse and repeat. @pamasaur | #midwestjs | thewebivore.com
  • 40. var assert = require('assert'); describe("An area of my application", function() { it("should know that 2 and 2 is 4", function(){ assert.equal(4, 2+2); }); }); @pamasaur | #midwestjs | thewebivore.com
  • 41. describe("An area of my application", function() { it("should know that 2 and 2 is 4", function(){ assert.equal(4, 2+2); }); }); @pamasaur | #midwestjs | thewebivore.com
  • 42. var assert = require('assert'); describe( , function() { it("should know that 2 and 2 is 4", function(){ assert.equal(4, 2+2); }); }); @pamasaur | #midwestjs | thewebivore.com
  • 43. var assert = require('assert'); describe("An area of my application", { it("should know that 2 and 2 is 4", { assert.equal(4, 2+2); }); }); @pamasaur | #midwestjs | thewebivore.com
  • 44. var assert = require('assert'); describe("An area of my application", function() { it( , function(){ }); }); @pamasaur | #midwestjs | thewebivore.com
  • 45. @pamasaur | #midwestjs | thewebivore.com
  • 47. Test describers • Jasmine • Mocha • QUnit • node-tap • YUI Test @pamasaur | #midwestjs | thewebivore.com
  • 48. Assertions • Chai • should.js • Expect.js • better-assert @pamasaur | #midwestjs | thewebivore.com
  • 49. Spies, stubs, and mocks • Sinon.js • Jest from Facebook @pamasaur | #midwestjs | thewebivore.com
  • 50. Test runners • Karma • Testem • YUI Yeti @pamasaur | #midwestjs | thewebivore.com
  • 51. Bringing testing into the fold 3 tips for making testing a regular part of your world
  • 52. #1: Teach testing • Attend talks like this! • Practice (ex. Code Retreat) • Pair programming @pamasaur | #midwestjs | thewebivore.com
  • 53. #2: Code coverage • Istanbul • Blanket.js @pamasaur | #midwestjs | thewebivore.com
  • 54. #3: Code review • Quality assurance • Mentoring • Don’t accept without tests! @pamasaur | #midwestjs | thewebivore.com
  • 55. What’d we learn? • Basics of testing • Writing a JavaScript test • Tools in JavaScript for testing • Ways to create a testing culture @pamasaur | #midwestjs | thewebivore.com
  • 57. TODO • Set up karma (our test runner) • With Jasmine (our assertion framework) @pamasaur | #midwestjs | thewebivore.com
  • 58. TODO • Write a failing test • Correct the failing test @pamasaur | #midwestjs | thewebivore.com
  • 59. TODO • Write another test • Setup in beforeEach @pamasaur | #midwestjs | thewebivore.com
  • 60. Thank you! • Find me online at • @pamasaur • thewebivore.com (blog) • turing.cool (podcast) • thewebivore.com/book (book!) @pamasaur | #midwestjs | thewebivore.com

Editor's Notes

  1. Fascinating data, and can help you monitor code quality over time
  2. Code review is great for 1m reasons, and enforcing testing is just one of them