Upload
premnath-thimma-csmpmp
View
109
Download
2
Embed Size (px)
Citation preview
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