SlideShare a Scribd company logo
UNIT TESTING USING JASMINE
JAVASCRIPT
IMPORTANCE OF UNIT TEST
 Makes the process Agile
 Improves the Quality of Code
 Finds application issues/bugs early
 Detect Changes that may break the design contract in refactoring
 Provide debugging process
 Provides documentation
 Reduces cost
AVAILABLE UNIT TEST FRAMEWORKS
Find more unit test frameworks - https://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#JavaScript
WHY JASMINE FRAMEWORK
 Behaviour driven development framework, also supports TDD
 Used for synchronous and asynchronous javascript code
 Does not rely on DOM or any browser
 Has built in assertion library and command line utility to run the tests
 Has simple syntax 
HELLO WORLD EXAMPLE
Javascript function –
- return ‘Hello World’ String
Unit test case for Javascript function –
- Calls actual function and matches the
output with expected output
INSTALL JASMINE FRAMEWORK
 Download latest version of Jasmine framework – click here
 Extract all the files
 Open ‘SpecRunner.html’ file
JASMINE FILE STRUCTURE
Boot Js –
this file "boots" Jasmine,
performing all of the
necessary initialization
before executing the
loaded environment and
all of a project's specs.
Spec folder -
Contains the Javascript
tesintg files unit test
files
Src folder -
Contains the Javascript
source files
Jasmine-html.js –
Javascript library which
has pure js functions to
capture the running
statistics of suits / specs
Jasmine.js –
Jasmine’s core engine
which responsible to
manage test life cycle
SpecRunner.html–
Test case runner HTML
file
CREATE TEST AND TEST SUITE
 describe(string suiteName) - Declare test suites using this function
 Group of all respective it() /test cases
 it (string testName) – Declare test case
 Write multiple it() calls in a single describe() function
 The string you passed to the describe() as the first parameter will be concatenated with the string passed to the
it(), to describe the complete name of the spec.
Syntax :
describe(‘Suite Name – Scenario name’, function() {
it(‘test case 1 name’, function() {
...
};
it(‘test case 2 name’, function() {
...
};
})
MATCHERS
• Any matcher can evaluate to a negative
assertion by chaining the call to expect with
a not before calling the matcher
• Each matcher implements a boolean
comparison between the actual value and
the expected value.
• It is responsible for reporting to Jasmine if
the expectation is true or false. Jasmine will
then pass or fail the spec.
LIST OF MATCHERS
SETUP AND TEARDOWN METHODS
 beforeEach() and afterEach() – runs before and after for every suite
 beforeAll() and afterAll() – runs before and after all the suites
before All afterAll
beforeEach
Test
afterEach
Test Suits
TEARDOWN METHODS EXAMPLE
beforeEach and afterEach Example beforeAll and afterAll Example
EXAMPLE - MATH.JS
• Create new file in SRC Folder
• Set file name as ‘Math.js’
• Create these functions for addition,
subtraction
• Make an entry in specRunner.html file
EXAMPLE - MATH-SPEC.JS
• Create new file in ‘spec’ Folder
• Set file name as ‘Math-spec.js’
• Make an entry in SpecRunner.html
file
JASMINE SPEC-RUNNER DASHBOARD
• Open SpecRunner.html file in any browser
• Calculator is the name of the ‘Test suite’
• Name start with ‘should’ are the spec /scenario
description
FAILING SPEC
 The fail () function causes a spec to fail.
 It can take a failure message or an Error object as a parameter.
FAILING SPEC RESULTS
THANK YOU

More Related Content

What's hot (20)

PPTX
Refactoring: Improving the design of existing code. Chapter 6.
Andrés Callejas González
 
PPTX
Unit Testing with Python
MicroPyramid .
 
PPTX
Unit testing using Munit Part 1
Anand kalla
 
PDF
Unit testing Ch. 13 of Programming Ruby
lvrubygroup
 
PPTX
TestNG vs Junit
Büşra İçöz
 
PPTX
Action filter
LearningTech
 
PPTX
Tdd & unit test
GomathiNayagam S
 
PPTX
Wix Automation - Test State Pattern - 11.9.16
Efrat Attas
 
PDF
Workshop unit test
Francesco Garavaglia
 
PPT
Intro to junit
Rakesh Srivastava
 
PPTX
Var arg methods
Rahul Sharma
 
PPTX
Part 11 sql model clause-return all rows
Girija Muscut
 
PPTX
Unit test
Tran Duc
 
PDF
Unit Testing in WordPress
Barry Kooij
 
PDF
Unit testing.pptx [repaired]
Mohammad Asmar
 
PPTX
Intro To Unit and integration Testing
Paul Churchward
 
PDF
JavaScript Unit Testing with an Angular 5.x Use Case 101
Hazem Saleh
 
PPTX
TestNG vs JUnit: cease fire or the end of the war
Oleksiy Rezchykov
 
PDF
TestNG Annotations in Selenium | Edureka
Edureka!
 
PPTX
Unit testing
Prabhat Kumar
 
Refactoring: Improving the design of existing code. Chapter 6.
Andrés Callejas González
 
Unit Testing with Python
MicroPyramid .
 
Unit testing using Munit Part 1
Anand kalla
 
Unit testing Ch. 13 of Programming Ruby
lvrubygroup
 
TestNG vs Junit
Büşra İçöz
 
Action filter
LearningTech
 
Tdd & unit test
GomathiNayagam S
 
Wix Automation - Test State Pattern - 11.9.16
Efrat Attas
 
Workshop unit test
Francesco Garavaglia
 
Intro to junit
Rakesh Srivastava
 
Var arg methods
Rahul Sharma
 
Part 11 sql model clause-return all rows
Girija Muscut
 
Unit test
Tran Duc
 
Unit Testing in WordPress
Barry Kooij
 
Unit testing.pptx [repaired]
Mohammad Asmar
 
Intro To Unit and integration Testing
Paul Churchward
 
JavaScript Unit Testing with an Angular 5.x Use Case 101
Hazem Saleh
 
TestNG vs JUnit: cease fire or the end of the war
Oleksiy Rezchykov
 
TestNG Annotations in Selenium | Edureka
Edureka!
 
Unit testing
Prabhat Kumar
 

Similar to Unit testing using jasmine in Javascript (20)

PPTX
jasmine
Asanka Indrajith
 
PDF
Quick tour to front end unit testing using jasmine
Gil Fink
 
PDF
Front end unit testing using jasmine
Gil Fink
 
PDF
Quick Tour to Front-End Unit Testing Using Jasmine
Gil Fink
 
PDF
Quick tour to front end unit testing using jasmine
Gil Fink
 
PDF
JavaScript TDD with Jasmine and Karma
Christopher Bartling
 
PPTX
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Samyak Bhalerao
 
PDF
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Christopher Bartling
 
PPTX
Jasmine framework
Vishwanath KC
 
PDF
Up & running with jasmine
kamarul kawnayeen
 
PPTX
Jasmine
Alok Guha
 
PPTX
Java Script Isn\'t a Toy Anymore
Alexis Williams
 
PPTX
Unit testing in JavaScript with Jasmine and Karma
Andrey Kolodnitsky
 
PPTX
Testing JavaScript with Jasmine in Rails Applications
Hector Correa
 
PPTX
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
Ortus Solutions, Corp
 
PPTX
Jasmine Testing to the Rescue!
Christopher Steele
 
PDF
Jasmine - why JS tests don't smell fishy
Igor Napierala
 
PPTX
Javascript Testing with Jasmine 101
Roy Yu
 
PDF
JAVASCRIPT Test Driven Development & Jasmine
Anup Singh
 
PDF
3 WAYS TO TEST YOUR COLDFUSION API
Gavin Pickin
 
Quick tour to front end unit testing using jasmine
Gil Fink
 
Front end unit testing using jasmine
Gil Fink
 
Quick Tour to Front-End Unit Testing Using Jasmine
Gil Fink
 
Quick tour to front end unit testing using jasmine
Gil Fink
 
JavaScript TDD with Jasmine and Karma
Christopher Bartling
 
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Samyak Bhalerao
 
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Christopher Bartling
 
Jasmine framework
Vishwanath KC
 
Up & running with jasmine
kamarul kawnayeen
 
Jasmine
Alok Guha
 
Java Script Isn\'t a Toy Anymore
Alexis Williams
 
Unit testing in JavaScript with Jasmine and Karma
Andrey Kolodnitsky
 
Testing JavaScript with Jasmine in Rails Applications
Hector Correa
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
Ortus Solutions, Corp
 
Jasmine Testing to the Rescue!
Christopher Steele
 
Jasmine - why JS tests don't smell fishy
Igor Napierala
 
Javascript Testing with Jasmine 101
Roy Yu
 
JAVASCRIPT Test Driven Development & Jasmine
Anup Singh
 
3 WAYS TO TEST YOUR COLDFUSION API
Gavin Pickin
 
Ad

Recently uploaded (20)

PDF
Introduction presentation of the patentbutler tool
MIPLM
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PDF
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
PPTX
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Council of Chalcedon Re-Examined
Smiling Lungs
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Introduction presentation of the patentbutler tool
MIPLM
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Controller Request and Response in Odoo18
Celine George
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Council of Chalcedon Re-Examined
Smiling Lungs
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Ad

Unit testing using jasmine in Javascript

  • 1. UNIT TESTING USING JASMINE JAVASCRIPT
  • 2. IMPORTANCE OF UNIT TEST  Makes the process Agile  Improves the Quality of Code  Finds application issues/bugs early  Detect Changes that may break the design contract in refactoring  Provide debugging process  Provides documentation  Reduces cost
  • 3. AVAILABLE UNIT TEST FRAMEWORKS Find more unit test frameworks - https://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#JavaScript
  • 4. WHY JASMINE FRAMEWORK  Behaviour driven development framework, also supports TDD  Used for synchronous and asynchronous javascript code  Does not rely on DOM or any browser  Has built in assertion library and command line utility to run the tests  Has simple syntax 
  • 5. HELLO WORLD EXAMPLE Javascript function – - return ‘Hello World’ String Unit test case for Javascript function – - Calls actual function and matches the output with expected output
  • 6. INSTALL JASMINE FRAMEWORK  Download latest version of Jasmine framework – click here  Extract all the files  Open ‘SpecRunner.html’ file
  • 7. JASMINE FILE STRUCTURE Boot Js – this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. Spec folder - Contains the Javascript tesintg files unit test files Src folder - Contains the Javascript source files Jasmine-html.js – Javascript library which has pure js functions to capture the running statistics of suits / specs Jasmine.js – Jasmine’s core engine which responsible to manage test life cycle SpecRunner.html– Test case runner HTML file
  • 8. CREATE TEST AND TEST SUITE  describe(string suiteName) - Declare test suites using this function  Group of all respective it() /test cases  it (string testName) – Declare test case  Write multiple it() calls in a single describe() function  The string you passed to the describe() as the first parameter will be concatenated with the string passed to the it(), to describe the complete name of the spec. Syntax : describe(‘Suite Name – Scenario name’, function() { it(‘test case 1 name’, function() { ... }; it(‘test case 2 name’, function() { ... }; })
  • 9. MATCHERS • Any matcher can evaluate to a negative assertion by chaining the call to expect with a not before calling the matcher • Each matcher implements a boolean comparison between the actual value and the expected value. • It is responsible for reporting to Jasmine if the expectation is true or false. Jasmine will then pass or fail the spec.
  • 11. SETUP AND TEARDOWN METHODS  beforeEach() and afterEach() – runs before and after for every suite  beforeAll() and afterAll() – runs before and after all the suites before All afterAll beforeEach Test afterEach Test Suits
  • 12. TEARDOWN METHODS EXAMPLE beforeEach and afterEach Example beforeAll and afterAll Example
  • 13. EXAMPLE - MATH.JS • Create new file in SRC Folder • Set file name as ‘Math.js’ • Create these functions for addition, subtraction • Make an entry in specRunner.html file
  • 14. EXAMPLE - MATH-SPEC.JS • Create new file in ‘spec’ Folder • Set file name as ‘Math-spec.js’ • Make an entry in SpecRunner.html file
  • 15. JASMINE SPEC-RUNNER DASHBOARD • Open SpecRunner.html file in any browser • Calculator is the name of the ‘Test suite’ • Name start with ‘should’ are the spec /scenario description
  • 16. FAILING SPEC  The fail () function causes a spec to fail.  It can take a failure message or an Error object as a parameter.