Introduction to Testing in AngularJS

This article is based on Misko Herveys presentation on testing in Angular.

  1. Learn to read code
  2. Mind your dependencies
  3. Setting up your environment
“Writing the test is easier than running the application.”
“It’s quicker than manually testing.”
“Writing more code (for defining tests) does NOT mean it takes longer than testing manually.”
It might be nearly 1:1 in amount of code but it’s fundamentally different in code structure. Application code can contain deep listing of loops etc while tests code is flat, essentially a sequential a series of describe, if, assert statements etc…

Image
“It’s hard to write tests and IT IS a skillset.”
Global state is hard to test as it’s hard to control.
“The difficulty of writing a test is to do with the structure of the code and what parts of it you can control through “mocking” functionality.”

Can Protractor and Karma be used together?

 

https://github.com/juliemr/protractor/issues/9#issuecomment-19927049

Protractor and Karma should not be used together; instead they provide separate systems for running tests. Protractor and Karma cover different aspects of testing – Karma is intended mostly for unit tests, while Protractor should be used for end to end testing.

Protractor is built on top of WebDriverJS, which uses a Selenium/WebDriver server to provision browsers and drive test execution. Examples of pure WebDriverJS can be found here:http://code.google.com/p/selenium/wiki/WebDriverJs

https://github.com/juliemr/protractor/issues/9#issuecomment-19931154

Georgios – I think it makes sense to keep Protractor and Karma separate – for end to end tests, you want the native event driving and flexibility of webdriver, while for unit tests you want fast execution and autowatching of files.

refs:

Sam is a passionate web developer, online entrepreneur and investor. In his spare time he enjoys coding, playing chess and reading.

One thought on “Introduction to Testing in AngularJS

Leave a Reply

Your email address will not be published. Required fields are marked *