SlideShare a Scribd company logo
AngularJS
Why AngularJS?
Migrating to AngularJS
Testing AngularJS

Testing is a core value of the AngularJS development team.
Are Some Tests Just Stupid?

Yes! You will probably write a lot of dumb tests.
So what is all this talk about testing?

Fact is web developers did not have many tools for testing until recently.
Testing is not yet a common practice in front-end development, but web apps
are becoming increasingly complex so Google created tools for testing their
own suite of web apps. Thanks to guys like Miško Hevery and other
AngularJS team members, Google made these tools open source and
available for everyone.
Essentially these tools provide:
proof of testing
a way to catch bugs before the client does
a way to ensure that new code does not break old code
testable code that is more maintainable
Writing Testable Code

Test Driven Development means that code is written to be testable.
Learn to think about code in a way that makes it testable.
Testable code is usually modular and easy to understand.
Code that is not written to be testable is usually untestable.
How to Actually Test
There are many testing frameworks out there.
Here are 3 of the most popular:

These frameworks are very much alike. Jasmine is typically used
with AngularJS, but you can use whatever you like.
Writing Tests with Jasmine
Download from GitHub: http://pivotal.github.io/jasmine
Typical directory structure

http://www.adobe.com/devnet/html5/articles/unit-test-javascript-applicationswith-jasmine.html
Writing Tests with Jasmine
describe("blogCtrl", function () {
it('Add a blog entry', inject(function($rootScope, $controller) {
var Ctrl = $controller('blogCtrl', {$scope: $rootScope.$new()});
Ctrl.addBlogEntry({“title”:”blog”, “content”:”blah blah”});
expect(scope.blogs.length).toEqual(1);
}));
it('Remove a blog entry by title', inject(function($rootScope, $controller) {
var Ctrl = $controller('blogCtrl', {$scope: $rootScope.$new()});
Ctrl.removeBlogbyTitle({“title”:”blog”});
expect(scope.blogs.length).toEqual(0);
}));
});
Running your Jasmine Tests
Running tests can be done manually or automatically.

Small, simple projects rarely need automatic testing. Test are written to
run whenever any major changes are done as a way of catching bugs
that you might not have expected.

Complex applications that have many people are working on them
generally benefit from automated tests because those tests can quickly
cover the entire code base in several seconds, catching bugs in
modules you may not have even been aware of.
Automated Testing with Karma

Karma is an open source project started by developers at Google. It automates
the testing process and has been used of for years to test everything from
AngularJS docs to Gmail.
It runs as a nodejs server and is framework agnostic meaning you can use it with
any testing or application framework.
Karma provides a fast way to auto-run unit tests for data models and logic.
Interactivity and DOM tests are not typically done with Karma.
Automated Testing with Karma
Setting up Karma
Install nodejs: http://nodejs.org

Install and run Karma with 3 commands using nodejs package manager
$ npm install -g karma – downloads and installs everything you need
$ karma init – answer some questions about where yous test scripts are and what
browser you want to use for testing

$ karma start – starts the karma server
End to End Testing with Protractor


Used for front-end DOM testing



Built on top of WebDriverJS and Selenium Server



Installed via NodeJS



Replaces the old ngScenario test runner



Uses Jasmine or Mocha



Does not use Karma



Tests are written for DOM elements



Tests are more “expensive” than Karma tests and run much slower
End to End Testing with Protractor
http://blog.envylabs.com/post/61403296076/testing-angularjs-apps-with-protractor
describe('Say Hello', function() {
ptor = protractor.getInstance();
beforeEach(function() {
ptor.get('#/');
button = ptor.findElement(protractor.By.className('btn-say-hello'));
button.click();
});
it('says hello', function() {
message = ptor.findElement(protractor.By.className('message'));
expect(message.getText()).toEqual('Hello!');
});
});
The Future of Front-end Testing
Front-end testing is incredibly boring – a task
reserved for interns or junior developers.
That is because until recently, front-end
testing was an entirely manual process.
Most universities and colleges still do not
offer courses on either front-end or back-end
testing, but an increasing number of realworld programming jobs now require at least
some experience with testing.
Automated testing systems will improve over
the next few years to bring us to an entirely
new level of reality in testing. Writing code
for testing scenarios will be as much a
required programming skill as writing the
code it is intended to test.
Ad

Recommended

Angularjs - Unit testing introduction
Angularjs - Unit testing introduction
Nir Kaufman
 
AngularJS Unit Testing w/Karma and Jasmine
AngularJS Unit Testing w/Karma and Jasmine
foxp2code
 
AngularJS Unit Test
AngularJS Unit Test
Chiew Carol
 
Unit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJS
Knoldus Inc.
 
Intro to testing Javascript with jasmine
Intro to testing Javascript with jasmine
Timothy Oxley
 
Intro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJS
Jim Lynch
 
AngularJS Unit Testing
AngularJS Unit Testing
Prince Norin
 
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Unit testing of java script and angularjs application using Karma Jasmine Fra...
Samyak Bhalerao
 
Test-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS Applications
FITC
 
Angular testing
Angular testing
Raissa Ferreira
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
Knoldus Inc.
 
Karma - JS Test Runner
Karma - JS Test Runner
Sebastiano Armeli
 
Unit testing in JavaScript with Jasmine and Karma
Unit testing in JavaScript with Jasmine and Karma
Andrey Kolodnitsky
 
Angular JS Unit Testing - Overview
Angular JS Unit Testing - Overview
Thirumal Sakthivel
 
Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015
Andrew Eisenberg
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and Karma
Christopher Bartling
 
Angular Unit Testing
Angular Unit Testing
Alessandro Giorgetti
 
Unit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma intro
Maurice De Beijer [MVP]
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
Gil Fink
 
Introduction to Protractor
Introduction to Protractor
Jie-Wei Wu
 
Advanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit Testing
Lars Thorup
 
Unit-testing and E2E testing in JS
Unit-testing and E2E testing in JS
Michael Haberman
 
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Codemotion
 
Painless JavaScript Testing with Jest
Painless JavaScript Testing with Jest
Michał Pierzchała
 
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Christopher Bartling
 
Agile JavaScript Testing
Agile JavaScript Testing
Scott Becker
 
Unit Testing JavaScript Applications
Unit Testing JavaScript Applications
Ynon Perek
 
Angular Unit Testing
Angular Unit Testing
Avi Engelshtein
 
Angular Testing
Angular Testing
Kourosh Sajjadi
 
Angular Unit testing.pptx
Angular Unit testing.pptx
RiyaBangera
 

More Related Content

What's hot (20)

Test-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS Applications
FITC
 
Angular testing
Angular testing
Raissa Ferreira
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
Knoldus Inc.
 
Karma - JS Test Runner
Karma - JS Test Runner
Sebastiano Armeli
 
Unit testing in JavaScript with Jasmine and Karma
Unit testing in JavaScript with Jasmine and Karma
Andrey Kolodnitsky
 
Angular JS Unit Testing - Overview
Angular JS Unit Testing - Overview
Thirumal Sakthivel
 
Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015
Andrew Eisenberg
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and Karma
Christopher Bartling
 
Angular Unit Testing
Angular Unit Testing
Alessandro Giorgetti
 
Unit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma intro
Maurice De Beijer [MVP]
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
Gil Fink
 
Introduction to Protractor
Introduction to Protractor
Jie-Wei Wu
 
Advanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit Testing
Lars Thorup
 
Unit-testing and E2E testing in JS
Unit-testing and E2E testing in JS
Michael Haberman
 
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Codemotion
 
Painless JavaScript Testing with Jest
Painless JavaScript Testing with Jest
Michał Pierzchała
 
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Christopher Bartling
 
Agile JavaScript Testing
Agile JavaScript Testing
Scott Becker
 
Unit Testing JavaScript Applications
Unit Testing JavaScript Applications
Ynon Perek
 
Angular Unit Testing
Angular Unit Testing
Avi Engelshtein
 
Test-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS Applications
FITC
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
Knoldus Inc.
 
Unit testing in JavaScript with Jasmine and Karma
Unit testing in JavaScript with Jasmine and Karma
Andrey Kolodnitsky
 
Angular JS Unit Testing - Overview
Angular JS Unit Testing - Overview
Thirumal Sakthivel
 
Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015
Andrew Eisenberg
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and Karma
Christopher Bartling
 
Unit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma intro
Maurice De Beijer [MVP]
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
Gil Fink
 
Introduction to Protractor
Introduction to Protractor
Jie-Wei Wu
 
Advanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit Testing
Lars Thorup
 
Unit-testing and E2E testing in JS
Unit-testing and E2E testing in JS
Michael Haberman
 
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
Codemotion
 
Painless JavaScript Testing with Jest
Painless JavaScript Testing with Jest
Michał Pierzchała
 
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Christopher Bartling
 
Agile JavaScript Testing
Agile JavaScript Testing
Scott Becker
 
Unit Testing JavaScript Applications
Unit Testing JavaScript Applications
Ynon Perek
 

Similar to Testing in AngularJS (20)

Angular Testing
Angular Testing
Kourosh Sajjadi
 
Angular Unit testing.pptx
Angular Unit testing.pptx
RiyaBangera
 
Slaven tomac unit testing in angular js
Slaven tomac unit testing in angular js
Slaven Tomac
 
JavaCro'14 - Unit testing in AngularJS – Slaven Tomac
JavaCro'14 - Unit testing in AngularJS – Slaven Tomac
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Unit Testing in Angular
Unit Testing in Angular
Knoldus Inc.
 
What the HTML? - The Holy Grail
What the HTML? - The Holy Grail
James Ford
 
Javascript tdd byandreapaciolla
Javascript tdd byandreapaciolla
Andrea Paciolla
 
AngularJS Testing
AngularJS Testing
Ahmed Elmehri
 
Angular Application Testing
Angular Application Testing
Troy Miles
 
Automated testing for client-side - Adam Klein, 500 Tech
Automated testing for client-side - Adam Klein, 500 Tech
Codemotion Tel Aviv
 
Client side unit tests - using jasmine & karma
Client side unit tests - using jasmine & karma
Adam Klein
 
JavaScript Unit Testing with an Angular 5.x Use Case 101
JavaScript Unit Testing with an Angular 5.x Use Case 101
Hazem Saleh
 
Front end unit testing using jasmine
Front end unit testing using jasmine
Gil Fink
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
Ortus Solutions, Corp
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
Gil Fink
 
Dive into Angular, part 5: Experience
Dive into Angular, part 5: Experience
Oleksii Prohonnyi
 
AngularJS Development Services
AngularJS Development Services
Kretoss Technology
 
Quick Tour to Front-End Unit Testing Using Jasmine
Quick Tour to Front-End Unit Testing Using Jasmine
Gil Fink
 
Front-end Testing (manual, automated, you name it) - Erich Jagomägis - Develo...
Front-end Testing (manual, automated, you name it) - Erich Jagomägis - Develo...
MobileMonday Estonia
 
UI Testing Best Practices - An Expected Journey
UI Testing Best Practices - An Expected Journey
Oren Farhi
 
Angular Unit testing.pptx
Angular Unit testing.pptx
RiyaBangera
 
Slaven tomac unit testing in angular js
Slaven tomac unit testing in angular js
Slaven Tomac
 
Unit Testing in Angular
Unit Testing in Angular
Knoldus Inc.
 
What the HTML? - The Holy Grail
What the HTML? - The Holy Grail
James Ford
 
Javascript tdd byandreapaciolla
Javascript tdd byandreapaciolla
Andrea Paciolla
 
Angular Application Testing
Angular Application Testing
Troy Miles
 
Automated testing for client-side - Adam Klein, 500 Tech
Automated testing for client-side - Adam Klein, 500 Tech
Codemotion Tel Aviv
 
Client side unit tests - using jasmine & karma
Client side unit tests - using jasmine & karma
Adam Klein
 
JavaScript Unit Testing with an Angular 5.x Use Case 101
JavaScript Unit Testing with an Angular 5.x Use Case 101
Hazem Saleh
 
Front end unit testing using jasmine
Front end unit testing using jasmine
Gil Fink
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
Ortus Solutions, Corp
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
Gil Fink
 
Dive into Angular, part 5: Experience
Dive into Angular, part 5: Experience
Oleksii Prohonnyi
 
AngularJS Development Services
AngularJS Development Services
Kretoss Technology
 
Quick Tour to Front-End Unit Testing Using Jasmine
Quick Tour to Front-End Unit Testing Using Jasmine
Gil Fink
 
Front-end Testing (manual, automated, you name it) - Erich Jagomägis - Develo...
Front-end Testing (manual, automated, you name it) - Erich Jagomägis - Develo...
MobileMonday Estonia
 
UI Testing Best Practices - An Expected Journey
UI Testing Best Practices - An Expected Journey
Oren Farhi
 
Ad

Recently uploaded (20)

ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
janeliewang985
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
janeliewang985
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
Ad

Testing in AngularJS

  • 4. Testing AngularJS Testing is a core value of the AngularJS development team.
  • 5. Are Some Tests Just Stupid? Yes! You will probably write a lot of dumb tests.
  • 6. So what is all this talk about testing? Fact is web developers did not have many tools for testing until recently. Testing is not yet a common practice in front-end development, but web apps are becoming increasingly complex so Google created tools for testing their own suite of web apps. Thanks to guys like Miško Hevery and other AngularJS team members, Google made these tools open source and available for everyone. Essentially these tools provide: proof of testing a way to catch bugs before the client does a way to ensure that new code does not break old code testable code that is more maintainable
  • 7. Writing Testable Code Test Driven Development means that code is written to be testable. Learn to think about code in a way that makes it testable. Testable code is usually modular and easy to understand. Code that is not written to be testable is usually untestable.
  • 8. How to Actually Test There are many testing frameworks out there. Here are 3 of the most popular: These frameworks are very much alike. Jasmine is typically used with AngularJS, but you can use whatever you like.
  • 9. Writing Tests with Jasmine Download from GitHub: http://pivotal.github.io/jasmine Typical directory structure http://www.adobe.com/devnet/html5/articles/unit-test-javascript-applicationswith-jasmine.html
  • 10. Writing Tests with Jasmine describe("blogCtrl", function () { it('Add a blog entry', inject(function($rootScope, $controller) { var Ctrl = $controller('blogCtrl', {$scope: $rootScope.$new()}); Ctrl.addBlogEntry({“title”:”blog”, “content”:”blah blah”}); expect(scope.blogs.length).toEqual(1); })); it('Remove a blog entry by title', inject(function($rootScope, $controller) { var Ctrl = $controller('blogCtrl', {$scope: $rootScope.$new()}); Ctrl.removeBlogbyTitle({“title”:”blog”}); expect(scope.blogs.length).toEqual(0); })); });
  • 11. Running your Jasmine Tests Running tests can be done manually or automatically. Small, simple projects rarely need automatic testing. Test are written to run whenever any major changes are done as a way of catching bugs that you might not have expected. Complex applications that have many people are working on them generally benefit from automated tests because those tests can quickly cover the entire code base in several seconds, catching bugs in modules you may not have even been aware of.
  • 12. Automated Testing with Karma Karma is an open source project started by developers at Google. It automates the testing process and has been used of for years to test everything from AngularJS docs to Gmail. It runs as a nodejs server and is framework agnostic meaning you can use it with any testing or application framework. Karma provides a fast way to auto-run unit tests for data models and logic. Interactivity and DOM tests are not typically done with Karma.
  • 14. Setting up Karma Install nodejs: http://nodejs.org Install and run Karma with 3 commands using nodejs package manager $ npm install -g karma – downloads and installs everything you need $ karma init – answer some questions about where yous test scripts are and what browser you want to use for testing $ karma start – starts the karma server
  • 15. End to End Testing with Protractor  Used for front-end DOM testing  Built on top of WebDriverJS and Selenium Server  Installed via NodeJS  Replaces the old ngScenario test runner  Uses Jasmine or Mocha  Does not use Karma  Tests are written for DOM elements  Tests are more “expensive” than Karma tests and run much slower
  • 16. End to End Testing with Protractor http://blog.envylabs.com/post/61403296076/testing-angularjs-apps-with-protractor describe('Say Hello', function() { ptor = protractor.getInstance(); beforeEach(function() { ptor.get('#/'); button = ptor.findElement(protractor.By.className('btn-say-hello')); button.click(); }); it('says hello', function() { message = ptor.findElement(protractor.By.className('message')); expect(message.getText()).toEqual('Hello!'); }); });
  • 17. The Future of Front-end Testing Front-end testing is incredibly boring – a task reserved for interns or junior developers. That is because until recently, front-end testing was an entirely manual process. Most universities and colleges still do not offer courses on either front-end or back-end testing, but an increasing number of realworld programming jobs now require at least some experience with testing. Automated testing systems will improve over the next few years to bring us to an entirely new level of reality in testing. Writing code for testing scenarios will be as much a required programming skill as writing the code it is intended to test.