SlideShare a Scribd company logo
JAVASCRIPT UNIT 
TESTING 
Pulak (@pulakb) 
http://www.pulakonline.com
What is unit testing?
What is unit testing? 
A unit test is an automated piece of code 
that invokes a unit of work in the system and 
then checks a single assumption about the 
behavior of that unit of work.
What is unit testing? 
A unit of work is a single logical functional 
use case in the system that can be invoked by 
some public interface (in most cases). 
A unit of work can span a single method, a 
whole class or multiple classes working together 
to achieve one single logical purpose that can be 
verified.
How to define good unit test?
How to define good unit test? 
Automated 
Repeatable Fast 
GOOD UNIT 
TEST 
Easy to run Incremental 
Easy to 
understand
Why we need unit testing?
Why we need unit testing? 
 Highly stable solution 
 Integration of different components will be easier 
 New and regression defects can be minimized 
 Good unit testing reduces the test cycle for each 
phrase 
 Good unit testing can be a good reference for the 
system documentation
Test-Driven Development
Test-Driven Development 
 Write test cases for a specific part of your code 
 Write your code to ‘fill in’ the tests. Your code only 
serves to make all of your tests pass, and nothing 
more 
 Once all your tests pass, go back and clean your 
code (Refactoring) 
TDD gives developers the power to think clearly about 
the specifications before they engage themselves with 
implementations.
Test-Driven Development 
Writing a failing test case 
Run the test, 
Fail? 
Write application code 
Run the tests, 
Success? 
Refactor 
? 
Refactor the code 
Yes 
Yes 
Yes 
No 
No 
No
Behavior-Driven Development 
 Write application code first. 
 Test cases must be small and tests one thing. Test a small 
unit of code instead of the entire application 
 Run test cases against class or method specific for that 
test case 
 If test fails, fix the defects and test again 
With BDD, you can write specifications that are small and easy 
to read.
Behavior-Driven Development 
Write class(es) or method(s) 
Write unit tests 
Run the tests, 
Fail? 
Refactor 
? 
Refactor the code 
No 
Yes 
No 
Yes 
Fix the defects
What is Jasmine?
What is Jasmine? 
Jasmine is a behavior-driven testing 
framework for JavaScript programming language. 
It does not depend on any other JavaScript 
frameworks. It does not require a DOM.
Resources 
http://jasmine.github.io/ 
http://jasmine.github.io/1.3/introduction.html 
http://jasmine.github.io/2.0/introduction.html 
https://github.com/pivotal/jasmine/tree/master/dist

More Related Content

PPSX
PPTX
TDD - Test Driven Development
PPT
Basic software-testing-concepts
PDF
Continuous testing
PPTX
Automation Tools Overview
PPT
Software Testing 101
PDF
Test Driven Development (TDD)
PDF
An Introduction to Test Driven Development
TDD - Test Driven Development
Basic software-testing-concepts
Continuous testing
Automation Tools Overview
Software Testing 101
Test Driven Development (TDD)
An Introduction to Test Driven Development

What's hot (20)

PPT
Basics of Software Testing
PPS
Unit Testing
PDF
4 Major Advantages of API Testing
PDF
Seminar on Software Testing
PDF
Jmeter Performance Testing
PDF
What is Integration Testing? | Edureka
PPT
Performance testing : An Overview
PDF
Unit and integration Testing
PPT
Automation testing
PPT
Software Testing Fundamentals
PPTX
functional testing
PPTX
Security Testing
PDF
PDF
An introduction to unit testing
PPT
Performance testing and reporting with JMeter
PDF
An Introduction To Automated API Testing
PPTX
Unit Testing Concepts and Best Practices
PDF
12 Steps to API Load Testing with Apache JMeter
PPTX
New relic
PPTX
Beautfiul world of Flutter Testing
Basics of Software Testing
Unit Testing
4 Major Advantages of API Testing
Seminar on Software Testing
Jmeter Performance Testing
What is Integration Testing? | Edureka
Performance testing : An Overview
Unit and integration Testing
Automation testing
Software Testing Fundamentals
functional testing
Security Testing
An introduction to unit testing
Performance testing and reporting with JMeter
An Introduction To Automated API Testing
Unit Testing Concepts and Best Practices
12 Steps to API Load Testing with Apache JMeter
New relic
Beautfiul world of Flutter Testing
Ad

Viewers also liked (16)

PDF
Client side unit tests - using jasmine & karma
PPT
Js unit testing
PDF
Cloud Platform as a Service: Heroku
PPTX
Unit Testing JavaScript with Jasmine
PPT
Testing Javascript with Jasmine
PDF
Story about module management with angular.js
PPT
TDD, unit testing and java script testing frameworks workshop
PDF
Angular testing
PDF
Angular 2 - What's new and what's different
PPTX
Unit testing JavaScript: Jasmine & karma intro
PPTX
JavaScript Promises
PDF
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
PDF
Advanced Jasmine - Front-End JavaScript Unit Testing
PDF
Karma - JS Test Runner
PDF
JavaScript TDD with Jasmine and Karma
PDF
Automated Web Testing using JavaScript
Client side unit tests - using jasmine & karma
Js unit testing
Cloud Platform as a Service: Heroku
Unit Testing JavaScript with Jasmine
Testing Javascript with Jasmine
Story about module management with angular.js
TDD, unit testing and java script testing frameworks workshop
Angular testing
Angular 2 - What's new and what's different
Unit testing JavaScript: Jasmine & karma intro
JavaScript Promises
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Advanced Jasmine - Front-End JavaScript Unit Testing
Karma - JS Test Runner
JavaScript TDD with Jasmine and Karma
Automated Web Testing using JavaScript
Ad

Similar to JavaScript Unit Testing (20)

PPTX
Unit testing & TDD concepts with best practice guidelines.
PPS
Why Unit Testingl
PPS
Why Unit Testingl
PPS
Why unit testingl
PPT
Unit Testing, TDD and the Walking Skeleton
PPTX
TDD - Agile
PDF
Unit testing, principles
PDF
Unit testing (Exploring the other side as a tester)
PPTX
Test driven development(tdd)
PPT
Test Driven Development - Overview and Adoption
PPTX
Software presentation
PDF
Introduction of unit test to management
PPTX
TDD Best Practices
PPTX
UNIT TESTING PPT
PPT
Automated Unit Testing and TDD
PPTX
Test Driven Development
PDF
TDD Workshop UTN 2012
PPTX
Test Driven Development
PDF
Keyword Driven Testing
Unit testing & TDD concepts with best practice guidelines.
Why Unit Testingl
Why Unit Testingl
Why unit testingl
Unit Testing, TDD and the Walking Skeleton
TDD - Agile
Unit testing, principles
Unit testing (Exploring the other side as a tester)
Test driven development(tdd)
Test Driven Development - Overview and Adoption
Software presentation
Introduction of unit test to management
TDD Best Practices
UNIT TESTING PPT
Automated Unit Testing and TDD
Test Driven Development
TDD Workshop UTN 2012
Test Driven Development
Keyword Driven Testing

Recently uploaded (20)

PDF
Triggering QUIC, presented by Geoff Huston at IETF 123
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PPTX
innovation process that make everything different.pptx
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PDF
Testing WebRTC applications at scale.pdf
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
PDF
Sims 4 Historia para lo sims 4 para jugar
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
DOCX
Unit-3 cyber security network security of internet system
PPTX
international classification of diseases ICD-10 review PPT.pptx
PPTX
Introduction to Information and Communication Technology
PPTX
SAP Ariba Sourcing PPT for learning material
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PPT
tcp ip networks nd ip layering assotred slides
PPTX
QR Codes Qr codecodecodecodecocodedecodecode
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
Triggering QUIC, presented by Geoff Huston at IETF 123
RPKI Status Update, presented by Makito Lay at IDNOG 10
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
Unit-1 introduction to cyber security discuss about how to secure a system
innovation process that make everything different.pptx
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Testing WebRTC applications at scale.pdf
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
Sims 4 Historia para lo sims 4 para jugar
Decoding a Decade: 10 Years of Applied CTI Discipline
Unit-3 cyber security network security of internet system
international classification of diseases ICD-10 review PPT.pptx
Introduction to Information and Communication Technology
SAP Ariba Sourcing PPT for learning material
Cloud-Scale Log Monitoring _ Datadog.pdf
An introduction to the IFRS (ISSB) Stndards.pdf
tcp ip networks nd ip layering assotred slides
QR Codes Qr codecodecodecodecocodedecodecode
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
Design_with_Watersergyerge45hrbgre4top (1).ppt

JavaScript Unit Testing

  • 1. JAVASCRIPT UNIT TESTING Pulak (@pulakb) http://www.pulakonline.com
  • 2. What is unit testing?
  • 3. What is unit testing? A unit test is an automated piece of code that invokes a unit of work in the system and then checks a single assumption about the behavior of that unit of work.
  • 4. What is unit testing? A unit of work is a single logical functional use case in the system that can be invoked by some public interface (in most cases). A unit of work can span a single method, a whole class or multiple classes working together to achieve one single logical purpose that can be verified.
  • 5. How to define good unit test?
  • 6. How to define good unit test? Automated Repeatable Fast GOOD UNIT TEST Easy to run Incremental Easy to understand
  • 7. Why we need unit testing?
  • 8. Why we need unit testing?  Highly stable solution  Integration of different components will be easier  New and regression defects can be minimized  Good unit testing reduces the test cycle for each phrase  Good unit testing can be a good reference for the system documentation
  • 10. Test-Driven Development  Write test cases for a specific part of your code  Write your code to ‘fill in’ the tests. Your code only serves to make all of your tests pass, and nothing more  Once all your tests pass, go back and clean your code (Refactoring) TDD gives developers the power to think clearly about the specifications before they engage themselves with implementations.
  • 11. Test-Driven Development Writing a failing test case Run the test, Fail? Write application code Run the tests, Success? Refactor ? Refactor the code Yes Yes Yes No No No
  • 12. Behavior-Driven Development  Write application code first.  Test cases must be small and tests one thing. Test a small unit of code instead of the entire application  Run test cases against class or method specific for that test case  If test fails, fix the defects and test again With BDD, you can write specifications that are small and easy to read.
  • 13. Behavior-Driven Development Write class(es) or method(s) Write unit tests Run the tests, Fail? Refactor ? Refactor the code No Yes No Yes Fix the defects
  • 15. What is Jasmine? Jasmine is a behavior-driven testing framework for JavaScript programming language. It does not depend on any other JavaScript frameworks. It does not require a DOM.
  • 16. Resources http://jasmine.github.io/ http://jasmine.github.io/1.3/introduction.html http://jasmine.github.io/2.0/introduction.html https://github.com/pivotal/jasmine/tree/master/dist