arrow_back Highly Interactive Charts using Angular Directives
Test Driven Angular JS Development
Submitted by Sreenath Nannat (@sreenathn) on Tuesday, 31 December 2013
This workshop is for giving a head start on faster, maintainable and behavioural tests for AngularJS using the Jasmine Test Framework and Karma test runner. At the end of the session, the attendees should be able to:
- Learn about basic unit testing.
- Use Jasmine and Karma for writing and running tests.
- Write tests for Angular Routes, Directives, Factories and Controllers.
- Get an overview of Grunt and Bower.
Writing tests has definite benefits especially in long term. But if we don’t have the right environment and tool set, it can be less fun and frustrating too. In this workshop we will be focusing on setting up the right environment with the right tools which makes test driven development enjoyable and sustainable.
Unit testing is made really easy in AngularJS because of its dependency injection, which allows us to isolate different parts of the system and write unit tests for each of them. We will be using Jasmine as the testing framework and Karma as the test runner.
Jasmine is the most popular unit testing framework for writing behavioural tests. It resembles RSpec, the popular testing framework in the Ruby On Rails world. It comes up with set of helper methods which wraps out all the mundane things, especially the test setup, and helps us focus on testing. Also, it has a pretty clean syntax which helps learning faster.
Karma is a test runner which basically facilitates running tests in our preferred environment, a real browser or a headless browser like PhantomJS. The best part is that it will blend well with most of the major Continuous Integration servers such as Jenkins, Travis etc..
We will also cover tools such as Bower, Grunt, which helps us to run the tests frequently to give us quick and frequent feedback, which is mandatory for unit testing.
Angular JS makes it easy to write unit tests and acceptance tests, But in this workshop we will be covering only unit testing in Angular.
- Familiarity with Angular JS and Test Driven Development is Preferred.
- Laptop with your preferred IDE. We will be using Sublime.
- NG-boilerplage - We prefer this to kickstarting the AngularJS Dev setup including the tools required for TDD