Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Testing Your Angular App

vjwilson
February 25, 2016

Testing Your Angular App

Talk given to the Charlotte Front-end Developers Meetup (CLT FED) on Thursday, February, 25, 2016

vjwilson

February 25, 2016
Tweet

More Decks by vjwilson

Other Decks in Programming

Transcript

  1. What We’re Going To Cover 1. Overview (a little about

    Angular, more about testing) 2. Setup for testing Angular 3. Examples of Angular Tests
  2. One of the Good Things “AngularJS was designed from ground

    up to be testable. It encourages behavior-view separation, comes pre- bundled with mocks, and takes full advantage of dependency injection.” -angularjs.org
  3. Levels of Granularity • Unit Testing • Integration Testing •

    System Testing • User Acceptance Testing
  4. Unit Tests • Test individuals functions • Isolate the “system

    under test” • Black box vs. white box testing • Run frequently • Serve as living documentation • Catch bugs before the QA stage
  5. TDD 1. Figure out what code needs to do 2.

    Write tests 3. Tests fail 4. Write code to make tests pass 5. Refactor 6. Repeat
  6. BDD 1. Establish goals / requirements 2. Whole team describes

    the behavior of the system 3. Code based on behavior decisions 4. Automate testing of the code (regression testing)
  7. Part the Second or How do you get going on

    this Angular testing thing?
  8. Install the pieces npm install phantomjs --save-dev npm install jasmine-core

    --save-dev npm install karma --save-dev npm install karma-jasmine --save-dev npm install karma-phantomjs-launcher --save-dev
  9. Configure Karma In a terminal, run karma init to create

    a karma.conf.js file: // list of files / patterns to load in the browser: [ 'bower_components/angular/angular.min.js', 'bower_components/angular-route/angular-route.min.js', 'bower_components/angular-mocks/angular-mocks.js', 'app.js', '*.js' ], ...Ω
  10. Parting Thoughts “Debugging is twice as hard as writing the

    code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” -Brian W. Kernighan