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

More Related Content

What's hot

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 Perlnohuhu
 
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
 
Protractor training
Protractor trainingProtractor training
Protractor training
Sergiy Stotskiy
 

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
 
A tale of 3 databases
A tale of 3 databasesA tale of 3 databases
A tale of 3 databases
 
Cypress workshop for JSFoo 2019
Cypress  workshop for JSFoo 2019Cypress  workshop for JSFoo 2019
Cypress workshop for JSFoo 2019
 
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
 
Why use Go for web development?
Why use Go for web development?Why use Go for web development?
Why use Go for web development?
 
Cypress first impressions
Cypress first impressionsCypress first impressions
Cypress first impressions
 
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
 
Using REST with VSTS and TFS
Using REST with VSTS and TFSUsing REST with VSTS and TFS
Using REST with VSTS and TFS
 
Paint it blue with PowerShell
Paint it blue with PowerShellPaint it blue with PowerShell
Paint it blue with PowerShell
 
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
 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern Javascript
 
Automated testing with Cypress
Automated testing with CypressAutomated testing with Cypress
Automated testing with Cypress
 
Conquering AngularJS Limitations
Conquering AngularJS LimitationsConquering AngularJS Limitations
Conquering AngularJS Limitations
 
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
 
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
 
Cypress - Best Practices
Cypress - Best PracticesCypress - Best Practices
Cypress - Best Practices
 
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
 
Protractor survival guide
Protractor survival guideProtractor survival guide
Protractor survival guide
 
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
 
Protractor training
Protractor trainingProtractor training
Protractor training
 

Similar to Unit Testing in JavaScript

Build automation best practices
Build automation best practicesBuild automation best practices
Build automation best practicesCode 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
Lars Thorup
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testingBestBrains
 
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
 
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
 
Unit Testing in R with Testthat - HRUG
Unit Testing in R with Testthat - HRUGUnit Testing in R with Testthat - HRUG
Unit Testing in R with Testthat - HRUG
egoodwintx
 
Hudson
HudsonHudson
Hudson
8x8
 

Similar to Unit Testing in JavaScript (20)

Build automation best practices
Build automation best practicesBuild automation best practices
Build automation best practices
 
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
 
Tools for Software Testing
Tools for Software TestingTools for Software Testing
Tools for Software Testing
 
Continuous Integration
Continuous IntegrationContinuous Integration
Continuous Integration
 
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
 
Test automation proposal
Test automation proposalTest automation proposal
Test automation proposal
 
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
 
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
 
Introduction to Automated Testing
Introduction to Automated TestingIntroduction to Automated Testing
Introduction to Automated Testing
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testing
 
Topic production code
Topic production codeTopic production code
Topic production code
 
Jenkins_1679702972.pdf
Jenkins_1679702972.pdfJenkins_1679702972.pdf
Jenkins_1679702972.pdf
 
jenkins.pdf
jenkins.pdfjenkins.pdf
jenkins.pdf
 
KrishnaToolComparisionPPT.pdf
KrishnaToolComparisionPPT.pdfKrishnaToolComparisionPPT.pdf
KrishnaToolComparisionPPT.pdf
 
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
 
Bootstrapping Quality
Bootstrapping QualityBootstrapping Quality
Bootstrapping Quality
 
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
 
Introduction to jenkins
Introduction to jenkinsIntroduction to jenkins
Introduction to jenkins
 
Unit Testing in R with Testthat - HRUG
Unit Testing in R with Testthat - HRUGUnit Testing in R with Testthat - HRUG
Unit Testing in R with Testthat - HRUG
 
Hudson
HudsonHudson
Hudson
 

Recently uploaded

GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 

Recently uploaded (20)

GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 

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