SlideShare a Scribd company logo
Unit Testing in
JavaScript
Robert Scaduto | @scardetto
Third Wave Technology
This talk was sponsored by:
About Me
• President and CTO of Third
Wave Technology
• Developing software
professionally since 1998
• Maintainer of a handful of
open source projects (Crux,
physique, build_number)
• Musician and aikido
practitioner
About Third Wave
• Boutique consulting firm
specializing in Agile
development
• Develop custom software for a
variety of languages and
platforms
• Strong focus on Agile
practices like Unit Testing and
Continuous Integration
What is Unit Testing?
• The practice of writing code to test individual
“units” in isolation.
• Originally conceived by Kent Beck in the
Smalltalk era. Made popular by JUnit.
• One of the pillars of Agile software development.
Why Unit Test?
• Speeds up the development cycle.
• Provides a safety net against enhancing or
refactoring existing code.
• Provides a living set of documentation about
how the code really works.
• Helps you write better code.
Better Design Through Tests
• Get immediate feedback from your API
decisions.
• Separates interface from implementation
concerns.
• Promotes the Single Responsibility Principle.
• Promotes the YAGNI principle.

(You Ain’t Gonna Need It!)
Foundation of Quality
• Unit testing is not a
replacement for other forms of
testing.
• However, it does make testing
easier by reducing uncertainty
in individual units.
• When combined with other
types of automated and
manual testing, you can have
a high degree of confidence in
the software.
Unit Testing Styles
• Test Driven Development (TDD) Style typically
structured via Arrange, Act, Assert (AAA).
• Behavior Driven Development (BDD) Style
• Both follow the Four Phase Test Form
Setup - Setup the unit under test.

Exercise - Exercise the unit and capture results.

Verify - Verify that the results meet expectations.

Teardown - Cleanup any side effects of the test.

TDD Style
The Good

Clearly shows how the API
will be used in “real” code.
The Caveat

Can lead to bigger tests that
are less self documenting.
BDD Style
The Good

Leads to self-documenting
specifications of units.
The Caveat

The test code is spread out
and may be harder to grok.
JavaScript Unit
Testing Frameworks
QUnit

http://qunit.js
• Developed by the jQuery
Team.
• Designed for testing in the
browser.
• However, it can be run from
the command line using a
headless browser like
phantomjs.
• Uses a TDD Style.
• Simple, flat syntax.
Jasmine

http://jasmine.github.io/
• Developed by Pivotal Labs.
• Designed to run in a DOM-
less environment.
• However, it can run in the
browser.
• BDD Style testing framework
heavily influenced by RSpec.
• Lots of built in features
including a fluent assertion
syntax and spies.
Honorable Mentions
• Mocha + Chai - http://mochajs.org | http://chaijs.com
• BDD framework with simple syntax.
• Limited built in features but plays nice with other libraries.
• Chai provides a very nice fluent assertions syntax.
• Jest - https://facebook.github.io/jest/
• Built on top of the Jasmine framework.
• Automatically mocks dependencies.
• Runs your tests using a fake DOM which makes it easy to run your tests
from the command line.
Which One Should You Use?
• Do you prefer a BDD or TDD syntax?
• Are you testing code that will always run in the
browser or will it run standalone?
• Are you using an application framework that
prefers one over another?
Live Demo
Thanks for Listening!
Tweet me if you have questions:

@scardetto
Source code available at:
github.com/scardetto/javascript-unit-testing-talk
Ad

More Related Content

What's hot (20)

Performance testing with VSTs on- and off-premises
Performance testing with VSTs on-  and off-premisesPerformance testing with VSTs on-  and off-premises
Performance testing with VSTs on- and off-premises
Jeff Bramwell
 
A tale of 3 databases
A tale of 3 databasesA tale of 3 databases
A tale of 3 databases
Chris Skardon
 
Cypress workshop for JSFoo 2019
Cypress  workshop for JSFoo 2019Cypress  workshop for JSFoo 2019
Cypress workshop for JSFoo 2019
Biswajit Pattanayak
 
Automated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and SeleniumAutomated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and Selenium
Dev9Com
 
Why use Go for web development?
Why use Go for web development?Why use Go for web development?
Why use Go for web development?
Weng Wei
 
Cypress first impressions
Cypress first impressionsCypress first impressions
Cypress first impressions
Hans Emmel
 
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil TayarCypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
Applitools
 
Using REST with VSTS and TFS
Using REST with VSTS and TFSUsing REST with VSTS and TFS
Using REST with VSTS and TFS
Jeff Bramwell
 
Paint it blue with PowerShell
Paint it blue with PowerShellPaint it blue with PowerShell
Paint it blue with PowerShell
Jaap Brasser
 
LONDON SDET MEETUP - Difference between Selenium and Cypress presentation
LONDON SDET MEETUP - Difference between Selenium and Cypress presentationLONDON SDET MEETUP - Difference between Selenium and Cypress presentation
LONDON SDET MEETUP - Difference between Selenium and Cypress presentation
Sriram Angajala
 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern Javascript
Wojciech Dzikowski
 
Automated testing with Cypress
Automated testing with CypressAutomated testing with Cypress
Automated testing with Cypress
Yong Shean Chong
 
Conquering AngularJS Limitations
Conquering AngularJS LimitationsConquering AngularJS Limitations
Conquering AngularJS Limitations
Valeri Karpov
 
Automating JavaScript testing with Jasmine and Perl
Automating JavaScript testing with Jasmine and PerlAutomating JavaScript testing with Jasmine and Perl
Automating JavaScript testing with Jasmine and Perl
nohuhu
 
Lessons in Open Source from the MongooseJS ODM
Lessons in Open Source from the MongooseJS ODMLessons in Open Source from the MongooseJS ODM
Lessons in Open Source from the MongooseJS ODM
Valeri Karpov
 
Cypress - Best Practices
Cypress - Best PracticesCypress - Best Practices
Cypress - Best Practices
Brian Mann
 
Use notes objects in memory and other useful java tips for xpages development
Use notes objects in memory and other useful java tips for xpages developmentUse notes objects in memory and other useful java tips for xpages development
Use notes objects in memory and other useful java tips for xpages development
Frank van der Linden
 
Protractor survival guide
Protractor survival guideProtractor survival guide
Protractor survival guide
László Andrási
 
Increase selenium tests stability via java script
Increase selenium tests stability via java scriptIncrease selenium tests stability via java script
Increase selenium tests stability via java script
Igor Khrol
 
Protractor training
Protractor trainingProtractor training
Protractor training
Sergiy Stotskiy
 
Performance testing with VSTs on- and off-premises
Performance testing with VSTs on-  and off-premisesPerformance testing with VSTs on-  and off-premises
Performance testing with VSTs on- and off-premises
Jeff Bramwell
 
A tale of 3 databases
A tale of 3 databasesA tale of 3 databases
A tale of 3 databases
Chris Skardon
 
Automated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and SeleniumAutomated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and Selenium
Dev9Com
 
Why use Go for web development?
Why use Go for web development?Why use Go for web development?
Why use Go for web development?
Weng Wei
 
Cypress first impressions
Cypress first impressionsCypress first impressions
Cypress first impressions
Hans Emmel
 
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil TayarCypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
Cypress vs Selenium WebDriver: Better, Or Just Different? -- by Gil Tayar
Applitools
 
Using REST with VSTS and TFS
Using REST with VSTS and TFSUsing REST with VSTS and TFS
Using REST with VSTS and TFS
Jeff Bramwell
 
Paint it blue with PowerShell
Paint it blue with PowerShellPaint it blue with PowerShell
Paint it blue with PowerShell
Jaap Brasser
 
LONDON SDET MEETUP - Difference between Selenium and Cypress presentation
LONDON SDET MEETUP - Difference between Selenium and Cypress presentationLONDON SDET MEETUP - Difference between Selenium and Cypress presentation
LONDON SDET MEETUP - Difference between Selenium and Cypress presentation
Sriram Angajala
 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern Javascript
Wojciech Dzikowski
 
Automated testing with Cypress
Automated testing with CypressAutomated testing with Cypress
Automated testing with Cypress
Yong Shean Chong
 
Conquering AngularJS Limitations
Conquering AngularJS LimitationsConquering AngularJS Limitations
Conquering AngularJS Limitations
Valeri Karpov
 
Automating JavaScript testing with Jasmine and Perl
Automating JavaScript testing with Jasmine and PerlAutomating JavaScript testing with Jasmine and Perl
Automating JavaScript testing with Jasmine and Perl
nohuhu
 
Lessons in Open Source from the MongooseJS ODM
Lessons in Open Source from the MongooseJS ODMLessons in Open Source from the MongooseJS ODM
Lessons in Open Source from the MongooseJS ODM
Valeri Karpov
 
Cypress - Best Practices
Cypress - Best PracticesCypress - Best Practices
Cypress - Best Practices
Brian Mann
 
Use notes objects in memory and other useful java tips for xpages development
Use notes objects in memory and other useful java tips for xpages developmentUse notes objects in memory and other useful java tips for xpages development
Use notes objects in memory and other useful java tips for xpages development
Frank van der Linden
 
Increase selenium tests stability via java script
Increase selenium tests stability via java scriptIncrease selenium tests stability via java script
Increase selenium tests stability via java script
Igor Khrol
 

Similar to Unit Testing in JavaScript (20)

Build automation best practices
Build automation best practicesBuild automation best practices
Build automation best practices
Code Mastery
 
10 Useful Testing Tools for Open Source Projects @ TuxCon 2015
10 Useful Testing Tools for Open Source Projects @ TuxCon 201510 Useful Testing Tools for Open Source Projects @ TuxCon 2015
10 Useful Testing Tools for Open Source Projects @ TuxCon 2015
Peter Sabev
 
Tools for Software Testing
Tools for Software TestingTools for Software Testing
Tools for Software Testing
Mohammed Moishin
 
Continuous Integration
Continuous IntegrationContinuous Integration
Continuous Integration
XPDays
 
Lean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill AyersLean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill Ayers
SPC Adriatics
 
Test automation proposal
Test automation proposalTest automation proposal
Test automation proposal
Mihai-Cristian Fratila
 
Microsoft power point automation-opensourcetestingtools_matrix-1
Microsoft power point   automation-opensourcetestingtools_matrix-1Microsoft power point   automation-opensourcetestingtools_matrix-1
Microsoft power point automation-opensourcetestingtools_matrix-1
tactqa
 
Microsoft power point automation-opensourcetestingtools_matrix-1
Microsoft power point   automation-opensourcetestingtools_matrix-1Microsoft power point   automation-opensourcetestingtools_matrix-1
Microsoft power point automation-opensourcetestingtools_matrix-1
tactqa
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testing
BestBrains
 
Introduction to Automated Testing
Introduction to Automated TestingIntroduction to Automated Testing
Introduction to Automated Testing
Lars Thorup
 
Jenkins an opensource CICD platform for all
Jenkins an opensource CICD platform for allJenkins an opensource CICD platform for all
Jenkins an opensource CICD platform for all
ssuserd7cedc
 
Topic production code
Topic production codeTopic production code
Topic production code
Kavi Kumar
 
Jenkins_1679702972.pdf
Jenkins_1679702972.pdfJenkins_1679702972.pdf
Jenkins_1679702972.pdf
MahmoudAlnmr1
 
jenkins.pdf
jenkins.pdfjenkins.pdf
jenkins.pdf
shahidafrith
 
KrishnaToolComparisionPPT.pdf
KrishnaToolComparisionPPT.pdfKrishnaToolComparisionPPT.pdf
KrishnaToolComparisionPPT.pdf
QA or the Highway
 
Buildmanagment tools mavenandgradle.pptx
Buildmanagment tools mavenandgradle.pptxBuildmanagment tools mavenandgradle.pptx
Buildmanagment tools mavenandgradle.pptx
praveena210336
 
Enter the mind of an Agile Developer
Enter the mind of an Agile DeveloperEnter the mind of an Agile Developer
Enter the mind of an Agile Developer
BSGAfrica
 
Bootstrapping Quality
Bootstrapping QualityBootstrapping Quality
Bootstrapping Quality
Michael Roufa
 
Making software development processes to work for you
Making software development processes to work for youMaking software development processes to work for you
Making software development processes to work for you
Ambientia
 
Introduction to jenkins
Introduction to jenkinsIntroduction to jenkins
Introduction to jenkins
Abe Diaz
 
Build automation best practices
Build automation best practicesBuild automation best practices
Build automation best practices
Code Mastery
 
10 Useful Testing Tools for Open Source Projects @ TuxCon 2015
10 Useful Testing Tools for Open Source Projects @ TuxCon 201510 Useful Testing Tools for Open Source Projects @ TuxCon 2015
10 Useful Testing Tools for Open Source Projects @ TuxCon 2015
Peter Sabev
 
Tools for Software Testing
Tools for Software TestingTools for Software Testing
Tools for Software Testing
Mohammed Moishin
 
Continuous Integration
Continuous IntegrationContinuous Integration
Continuous Integration
XPDays
 
Lean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill AyersLean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill Ayers
SPC Adriatics
 
Microsoft power point automation-opensourcetestingtools_matrix-1
Microsoft power point   automation-opensourcetestingtools_matrix-1Microsoft power point   automation-opensourcetestingtools_matrix-1
Microsoft power point automation-opensourcetestingtools_matrix-1
tactqa
 
Microsoft power point automation-opensourcetestingtools_matrix-1
Microsoft power point   automation-opensourcetestingtools_matrix-1Microsoft power point   automation-opensourcetestingtools_matrix-1
Microsoft power point automation-opensourcetestingtools_matrix-1
tactqa
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testing
BestBrains
 
Introduction to Automated Testing
Introduction to Automated TestingIntroduction to Automated Testing
Introduction to Automated Testing
Lars Thorup
 
Jenkins an opensource CICD platform for all
Jenkins an opensource CICD platform for allJenkins an opensource CICD platform for all
Jenkins an opensource CICD platform for all
ssuserd7cedc
 
Topic production code
Topic production codeTopic production code
Topic production code
Kavi Kumar
 
Jenkins_1679702972.pdf
Jenkins_1679702972.pdfJenkins_1679702972.pdf
Jenkins_1679702972.pdf
MahmoudAlnmr1
 
KrishnaToolComparisionPPT.pdf
KrishnaToolComparisionPPT.pdfKrishnaToolComparisionPPT.pdf
KrishnaToolComparisionPPT.pdf
QA or the Highway
 
Buildmanagment tools mavenandgradle.pptx
Buildmanagment tools mavenandgradle.pptxBuildmanagment tools mavenandgradle.pptx
Buildmanagment tools mavenandgradle.pptx
praveena210336
 
Enter the mind of an Agile Developer
Enter the mind of an Agile DeveloperEnter the mind of an Agile Developer
Enter the mind of an Agile Developer
BSGAfrica
 
Bootstrapping Quality
Bootstrapping QualityBootstrapping Quality
Bootstrapping Quality
Michael Roufa
 
Making software development processes to work for you
Making software development processes to work for youMaking software development processes to work for you
Making software development processes to work for you
Ambientia
 
Introduction to jenkins
Introduction to jenkinsIntroduction to jenkins
Introduction to jenkins
Abe Diaz
 
Ad

Recently uploaded (20)

The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Salesforce AI Associate 2 of 2 Certification.docx
Salesforce AI Associate 2 of 2 Certification.docxSalesforce AI Associate 2 of 2 Certification.docx
Salesforce AI Associate 2 of 2 Certification.docx
José Enrique López Rivera
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Automation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From AnywhereAutomation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From Anywhere
Lynda Kane
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
Lynda Kane
 
Asthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdfAsthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdf
VanessaRaudez
 
Network Security. Different aspects of Network Security.
Network Security. Different aspects of Network Security.Network Security. Different aspects of Network Security.
Network Security. Different aspects of Network Security.
gregtap1
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko
Fwdays
 
Image processinglab image processing image processing
Image processinglab image processing  image processingImage processinglab image processing  image processing
Image processinglab image processing image processing
RaghadHany
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Learn the Basics of Agile Development: Your Step-by-Step Guide
Learn the Basics of Agile Development: Your Step-by-Step GuideLearn the Basics of Agile Development: Your Step-by-Step Guide
Learn the Basics of Agile Development: Your Step-by-Step Guide
Marcel David
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Salesforce AI Associate 2 of 2 Certification.docx
Salesforce AI Associate 2 of 2 Certification.docxSalesforce AI Associate 2 of 2 Certification.docx
Salesforce AI Associate 2 of 2 Certification.docx
José Enrique López Rivera
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Automation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From AnywhereAutomation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From Anywhere
Lynda Kane
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
#AdminHour presents: Hour of Code2018 slide deck from 12/6/2018
Lynda Kane
 
Asthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdfAsthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdf
VanessaRaudez
 
Network Security. Different aspects of Network Security.
Network Security. Different aspects of Network Security.Network Security. Different aspects of Network Security.
Network Security. Different aspects of Network Security.
gregtap1
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko
Fwdays
 
Image processinglab image processing image processing
Image processinglab image processing  image processingImage processinglab image processing  image processing
Image processinglab image processing image processing
RaghadHany
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Learn the Basics of Agile Development: Your Step-by-Step Guide
Learn the Basics of Agile Development: Your Step-by-Step GuideLearn the Basics of Agile Development: Your Step-by-Step Guide
Learn the Basics of Agile Development: Your Step-by-Step Guide
Marcel David
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Ad

Unit Testing in JavaScript

  • 1. Unit Testing in JavaScript Robert Scaduto | @scardetto Third Wave Technology
  • 2. This talk was sponsored by:
  • 3. About Me • President and CTO of Third Wave Technology • Developing software professionally since 1998 • Maintainer of a handful of open source projects (Crux, physique, build_number) • Musician and aikido practitioner
  • 4. About Third Wave • Boutique consulting firm specializing in Agile development • Develop custom software for a variety of languages and platforms • Strong focus on Agile practices like Unit Testing and Continuous Integration
  • 5. What is Unit Testing? • The practice of writing code to test individual “units” in isolation. • Originally conceived by Kent Beck in the Smalltalk era. Made popular by JUnit. • One of the pillars of Agile software development.
  • 6. Why Unit Test? • Speeds up the development cycle. • Provides a safety net against enhancing or refactoring existing code. • Provides a living set of documentation about how the code really works. • Helps you write better code.
  • 7. Better Design Through Tests • Get immediate feedback from your API decisions. • Separates interface from implementation concerns. • Promotes the Single Responsibility Principle. • Promotes the YAGNI principle.
 (You Ain’t Gonna Need It!)
  • 8. Foundation of Quality • Unit testing is not a replacement for other forms of testing. • However, it does make testing easier by reducing uncertainty in individual units. • When combined with other types of automated and manual testing, you can have a high degree of confidence in the software.
  • 9. Unit Testing Styles • Test Driven Development (TDD) Style typically structured via Arrange, Act, Assert (AAA). • Behavior Driven Development (BDD) Style • Both follow the Four Phase Test Form Setup - Setup the unit under test.
 Exercise - Exercise the unit and capture results.
 Verify - Verify that the results meet expectations.
 Teardown - Cleanup any side effects of the test.

  • 10. TDD Style The Good
 Clearly shows how the API will be used in “real” code. The Caveat
 Can lead to bigger tests that are less self documenting.
  • 11. BDD Style The Good
 Leads to self-documenting specifications of units. The Caveat
 The test code is spread out and may be harder to grok.
  • 13. QUnit
 http://qunit.js • Developed by the jQuery Team. • Designed for testing in the browser. • However, it can be run from the command line using a headless browser like phantomjs. • Uses a TDD Style. • Simple, flat syntax.
  • 14. Jasmine
 http://jasmine.github.io/ • Developed by Pivotal Labs. • Designed to run in a DOM- less environment. • However, it can run in the browser. • BDD Style testing framework heavily influenced by RSpec. • Lots of built in features including a fluent assertion syntax and spies.
  • 15. Honorable Mentions • Mocha + Chai - http://mochajs.org | http://chaijs.com • BDD framework with simple syntax. • Limited built in features but plays nice with other libraries. • Chai provides a very nice fluent assertions syntax. • Jest - https://facebook.github.io/jest/ • Built on top of the Jasmine framework. • Automatically mocks dependencies. • Runs your tests using a fake DOM which makes it easy to run your tests from the command line.
  • 16. Which One Should You Use? • Do you prefer a BDD or TDD syntax? • Are you testing code that will always run in the browser or will it run standalone? • Are you using an application framework that prefers one over another?
  • 18. Thanks for Listening! Tweet me if you have questions:
 @scardetto Source code available at: github.com/scardetto/javascript-unit-testing-talk