SlideShare a Scribd company logo
1 of 12
JavaScript
Unit Test & Code Coverage
Premnath Thimma
Thought
A solution is only as good as your
understanding of the problem.
Thought
Why Unit Test?
• Promote better design – loose coupling
• Helps developers to write
– Testable unit
– Maintainable code
• Improves quality at unit level
Difficulties/Problems
• Lack of structure
• Function not exposed outside
• Complexity in the function ( > 10 lines )
• Tight coupling between components
Solutions from AngularJS
• Structure
– Module, Model, View, Controller, Service,
Templates, Filters
• Function not exposed outside
– Service, Factory, Constant, Value
• Complexity in the function ( > 10 lines )
– Module, Injectable Components
• Tight coupling between components
– Loose coupling with Structure, Module
Tools
• JS Libraries
– Jasmine, Qunit, Mocha
• Test Runner
– Chutzpah
• Visual Studio Plug-ins
– Chutzpah Test Adapter for the Test Explorer
– Chutzpah Test Runner Context Menu Extension
– Karma Test Adapter
Get to know Jasmine
• Supports BDD (User Story)
– Spec (describe, it)
– Nest-able Spec
• Powerful Matchers (+ Customer Matcher)
• Powerful concept like Spy
• Supported by Visual Studio
– Test Explorer (includes JS Unit Tests)
– Recognizes your changes to Unit Test
Get to know Chutzpah
• Test Runner
– Right Click and Run
– Runs automatically in Visual Studio when you
make changes to Unit Test
• Code Coverage
– From Visual Studio
– From Command Line
– Exclude and Include files using expression
– Context sensitive to File or Folder
Demo
Questions
References
• https://github.com/mmanela/chutzpah
• http://chutzpah.codeplex.com/documentation
• http://jasmine.github.io/edge/introduction.html
• https://docs.angularjs.org/guide/unit-testing

More Related Content

Similar to Unit Testing JavaScript with Jasmine

Rational Team Concert Process Customization - What you can and cannot do
Rational Team Concert Process Customization - What you can and cannot doRational Team Concert Process Customization - What you can and cannot do
Rational Team Concert Process Customization - What you can and cannot doRalph Schoon
 
Interconnect session 1888: Rational Team Concert Process Customization: What ...
Interconnect session 1888: Rational Team Concert Process Customization: What ...Interconnect session 1888: Rational Team Concert Process Customization: What ...
Interconnect session 1888: Rational Team Concert Process Customization: What ...Rosa Naranjo
 
Continuous test automation
Continuous test automationContinuous test automation
Continuous test automationMacharla Pradeep
 
Episode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in SalesforceEpisode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in SalesforceJitendra Zaa
 
Skillwise Unit Testing
Skillwise Unit TestingSkillwise Unit Testing
Skillwise Unit TestingSkillwise Group
 
Vikas_CV_Testing - Welspun - SalesForce
Vikas_CV_Testing  - Welspun - SalesForceVikas_CV_Testing  - Welspun - SalesForce
Vikas_CV_Testing - Welspun - SalesForceVikas Kiroula
 
Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014Red Gate Software
 
Agile testing
Agile testingAgile testing
Agile testingRaj Indugula
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0Ganesh Kondal
 
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...Codecamp Romania
 
SF1 - Apex Development Best Practises
SF1 - Apex Development Best PractisesSF1 - Apex Development Best Practises
SF1 - Apex Development Best PractisesSebastian Wagner
 
Leveraging HP Performance Center
Leveraging HP Performance CenterLeveraging HP Performance Center
Leveraging HP Performance CenterMartin Spier
 
Sledgehammer to Fine Brush for QA
Sledgehammer to Fine Brush for QASledgehammer to Fine Brush for QA
Sledgehammer to Fine Brush for QAShelley Lambert
 
Battle for Code Quality - A Story of One Java Project
Battle for Code Quality - A Story of One Java ProjectBattle for Code Quality - A Story of One Java Project
Battle for Code Quality - A Story of One Java ProjectGlobalLogic Ukraine
 
Sunil sharanappa senior automation test engineer profile
Sunil sharanappa senior automation test engineer profileSunil sharanappa senior automation test engineer profile
Sunil sharanappa senior automation test engineer profileSunil Sharanappa
 
Test Automation - Presented by Nagarajan, Architect @ TechCafe-2014
Test Automation - Presented by Nagarajan, Architect @ TechCafe-2014Test Automation - Presented by Nagarajan, Architect @ TechCafe-2014
Test Automation - Presented by Nagarajan, Architect @ TechCafe-2014Neev Technologies
 
Test Automation Architecture That Works by Bhupesh Dahal
Test Automation Architecture That Works by Bhupesh DahalTest Automation Architecture That Works by Bhupesh Dahal
Test Automation Architecture That Works by Bhupesh DahalQA or the Highway
 

Similar to Unit Testing JavaScript with Jasmine (20)

ApoorvaTiwari
ApoorvaTiwariApoorvaTiwari
ApoorvaTiwari
 
Rational Team Concert Process Customization - What you can and cannot do
Rational Team Concert Process Customization - What you can and cannot doRational Team Concert Process Customization - What you can and cannot do
Rational Team Concert Process Customization - What you can and cannot do
 
Interconnect session 1888: Rational Team Concert Process Customization: What ...
Interconnect session 1888: Rational Team Concert Process Customization: What ...Interconnect session 1888: Rational Team Concert Process Customization: What ...
Interconnect session 1888: Rational Team Concert Process Customization: What ...
 
Continuous test automation
Continuous test automationContinuous test automation
Continuous test automation
 
Episode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in SalesforceEpisode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in Salesforce
 
Skillwise Unit Testing
Skillwise Unit TestingSkillwise Unit Testing
Skillwise Unit Testing
 
Vikas_CV_Testing - Welspun - SalesForce
Vikas_CV_Testing  - Welspun - SalesForceVikas_CV_Testing  - Welspun - SalesForce
Vikas_CV_Testing - Welspun - SalesForce
 
Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014
 
Agile testing
Agile testingAgile testing
Agile testing
 
Presentation delex
Presentation delexPresentation delex
Presentation delex
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
 
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
 
SF1 - Apex Development Best Practises
SF1 - Apex Development Best PractisesSF1 - Apex Development Best Practises
SF1 - Apex Development Best Practises
 
Leveraging HP Performance Center
Leveraging HP Performance CenterLeveraging HP Performance Center
Leveraging HP Performance Center
 
Sledgehammer to Fine Brush for QA
Sledgehammer to Fine Brush for QASledgehammer to Fine Brush for QA
Sledgehammer to Fine Brush for QA
 
Battle for Code Quality - A Story of One Java Project
Battle for Code Quality - A Story of One Java ProjectBattle for Code Quality - A Story of One Java Project
Battle for Code Quality - A Story of One Java Project
 
Sunil sharanappa senior automation test engineer profile
Sunil sharanappa senior automation test engineer profileSunil sharanappa senior automation test engineer profile
Sunil sharanappa senior automation test engineer profile
 
Test Automation - Presented by Nagarajan, Architect @ TechCafe-2014
Test Automation - Presented by Nagarajan, Architect @ TechCafe-2014Test Automation - Presented by Nagarajan, Architect @ TechCafe-2014
Test Automation - Presented by Nagarajan, Architect @ TechCafe-2014
 
Test automation within a scrum process
Test automation within a scrum processTest automation within a scrum process
Test automation within a scrum process
 
Test Automation Architecture That Works by Bhupesh Dahal
Test Automation Architecture That Works by Bhupesh DahalTest Automation Architecture That Works by Bhupesh Dahal
Test Automation Architecture That Works by Bhupesh Dahal
 

Recently uploaded

Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the weldingMuhammadUzairLiaqat
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgsaravananr517913
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptMadan Karki
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptJasonTagapanGulla
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction managementMariconPadriquez1
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 

Recently uploaded (20)

Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the welding
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.ppt
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.ppt
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction management
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 

Unit Testing JavaScript with Jasmine

  • 1. JavaScript Unit Test & Code Coverage Premnath Thimma
  • 2. Thought A solution is only as good as your understanding of the problem.
  • 4. Why Unit Test? • Promote better design – loose coupling • Helps developers to write – Testable unit – Maintainable code • Improves quality at unit level
  • 5. Difficulties/Problems • Lack of structure • Function not exposed outside • Complexity in the function ( > 10 lines ) • Tight coupling between components
  • 6. Solutions from AngularJS • Structure – Module, Model, View, Controller, Service, Templates, Filters • Function not exposed outside – Service, Factory, Constant, Value • Complexity in the function ( > 10 lines ) – Module, Injectable Components • Tight coupling between components – Loose coupling with Structure, Module
  • 7. Tools • JS Libraries – Jasmine, Qunit, Mocha • Test Runner – Chutzpah • Visual Studio Plug-ins – Chutzpah Test Adapter for the Test Explorer – Chutzpah Test Runner Context Menu Extension – Karma Test Adapter
  • 8. Get to know Jasmine • Supports BDD (User Story) – Spec (describe, it) – Nest-able Spec • Powerful Matchers (+ Customer Matcher) • Powerful concept like Spy • Supported by Visual Studio – Test Explorer (includes JS Unit Tests) – Recognizes your changes to Unit Test
  • 9. Get to know Chutzpah • Test Runner – Right Click and Run – Runs automatically in Visual Studio when you make changes to Unit Test • Code Coverage – From Visual Studio – From Command Line – Exclude and Include files using expression – Context sensitive to File or Folder
  • 10. Demo
  • 12. References • https://github.com/mmanela/chutzpah • http://chutzpah.codeplex.com/documentation • http://jasmine.github.io/edge/introduction.html • https://docs.angularjs.org/guide/unit-testing