The main purpose of Karma is to make your TDD development easy, fast, and fun.
When should I use Karma?
- You want to test code in real browsers.
- You want to test code in multiple browsers (desktop, mobile, tablets, etc.).
- You want to execute your tests locally during development.
- You want to execute your tests on a continuous integration server.
- You want to execute your tests on every save.
- You love your terminal.
- You don't want your (testing) life to suck.
- You want to use Istanbul to automagically generate coverage reports.
- You want to use RequireJS for your source files.
But I still want to use _insert testing library_
Karma is not a testing framework, neither an assertion library. Karma just launches a HTTP server, and generates the test runner HTML file you probably already know from your favourite testing framework. So for testing purposes you can use pretty much anything you like. Right now out of the box there is support for
- _anything else_ Write your own adapter. It's not that hard. And we are here to help.
If you want to use one or more frameworks with Karma, then please read the documentation of the related adapters! It will help a lot about how to configure your project...
Which Browsers can I use?
All the major browsers are supported, if you want to know more see the Browsers page.
My tests are running really slow
If you're testing in the browser, make sure the Karma tab is the active tab. If you're using LiveReload to develop, try opening a second browser window so Karma can always be active.
Make sure you're not watching too many files. Set your
config.LOG_DEBUGto see how many files are being watched.
I want to use it. Where do I sign?
You don't need to sign anything but here are some resources to help you to get started. And if you need even more infos have a look at our great website.
Every serious project has a screencast, so here is ours. Just click here and let the show begin.
If you have Node.js installed, it's as simple as
$ npm install -g karma
This will give you the latest stable version available on npm. If you want to live life on the edge you can do so by
$ npm install -g karma@canary
The curious can have a look at the documentation articles for [Getting Started] and Versioning.
You can find a simple example in test/client/karma.conf.js which contains most of the options.
To create your own from scratch there is the
init command, which
will be named
karma.conf.js by default:
$ karma init
This will ask you many questions and if you answered them all correct you will be allowed to use Karma.
For more information on the configuration options see Configuration File Overview.
Now that you have your configuration all that is left to do is to start Karma:
$ karma start
That command starts a HTTP server and connects it to one or more browser window. It creates a test runner HTML file as well.
The HTTP server configuration and the test runner is generated from your Karma configuration.
file patterns in the Karma configuration are very important, because Karma creates HTML script elements
from the files matching a
file pattern with short pattern syntax or
So these matching files will be included directly into the test runner HTML file.
If you want to use a static file in your tests, then you have to turn off the
include flag by its
If you want to run tests manually (without auto watching file changes), you can:
$ karma run
By executing that command, Karma runs your test runner HTML file in the opened browser window and sends back the results to your test reporter. Many reporters are supported, for example you can use the IntelliJ reporter for WebStorm. You can of course create your own reporter if your want. Please let us know if you need any help!
Why did you create this?
I still don't get it. Where can I get help?
This is so great. I want to help.
My boss wants a license. So where is it?
The MIT License
Copyright (C) 2011-2013 Vojta Jína.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.