By Geertjan-Oracle on Nov 22, 2013
Karma (karma-runner.github.io), formerly known as Testacular, by the same guys who created AngularJS, automates testing by automatically kicking off test runs whenever you make changes to a test.
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. Because getting quick feedback is what makes you productive and creative.
I attended a great session on Karma by Brian Ford at Devoxx this year and here's a good document on it, showing how to take a few hours to do what I describe below in a few minutes. Also, here's an excellent intro by Vojta Jina, the main Karma guy:
While support for Jasmine in the context of NetBeans IDE has already been documented, Karma integration is now in the works. Below, let's take a look at what the new Karma integration consists of, aimed at making all Karma-related tasks easy and intuitive. After all, setting up a test runner should be a trivial administrative task, rather than the latest release of mission impossible.
To get Karma set up, start by running the following:
- npm install -g karma
- npm install -g karma-junit-reporter
- npm install -g karma-ng-scenario
Then, create a new application from the AngularJS Seed template, e.g., from the New Project dialog, which shows you the following when you open it into NetBeans IDE:
Take note of the "Karma" node, right at the end of the logical view above. Right-click it to see the Karma actions. Choose the configuration file you'd like to work with:
When you try to start Karma without choosing a configuration file, the dialog below opens:
Choose the configuration file you'd like to use and click the "Watch" checkbox:
Next, try start Karma, by right-clicking the node and choosing Run. An error is shown if your browser hasn't been configured correctly:
Below you can see that I changed the "browsers" configuration, so that the full path to the browser is registered. Another error is shown if the "karma-script-launcher" module hasn't been registered, which I did below after seeing the error message:
Now, whenever you make changes to a test and save it, Karma automatically processes the test and shows you the results, whether positive....
...or less positive:
Note: All of the above is currently in development builds for the next version of NetBeans IDE, i.e., not available yet in NetBeans IDE 7.4.