Angular.js is one of the most widely-used web frameworks today. Part of what makes Angular so amazing is that it is a framework written from the ground up with testing in mind.
Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: requirements are turned into very specific test cases, then the software is improved to pass the new tests, only. This is opposed to software development that allows software to be added that is not proven to meet requirements.
Karma: The main goal for Karma is to bring a productive testing environment to developers. The environment being one where they don’t have to set up loads of configurations, but rather a place where developers can just write the code and get instant feedback from their tests. Karma is a browser test runner.
The idea is that browsers do not have natively a concept of loading tests files, running them, and reporting results. What Karma does is (roughly):
1. Start a small web server to serve “client-side” JavaScript files to be tested.
2. Also serve the “client-side” JavaScript files with the tests (or Specs, as they’re often called)
3. Serve a custom web page that will run JavaScript code for the tests
4. Start a browser to load this page
5. Report the results of the test to the server
6. Karma can then report the results to text files, the console or anything your CI server likes.
Use: Karma can be used to run your tests in browsers. If your tests are simple JavaScript that would run the same in Node as in Chrome, this is not necessary, but if you wish to support Firefox, Chrome, IE, et al, in your tests, Karma lets you do it, via a configuration file.
Leave a comment