Karma: AngularJS Automated Test Runner

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:

As Vojta says, above, the main feature of Karma is its workflow, i.e., that you can save tests and immediately get feedback. Another excellent presentation, by @yearofmoo, on this topic is here.

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.

Comments:

Hi,

Just tried NetBeans IDE Dev (Build 201311210002).

"Karma" node does not appear.

Posted by Cuneyt Ozen on November 24, 2013 at 03:34 PM PST #

It's not there yet. Drop me an email at geertjan.wielenga@oracle.com and I will point you to the right build, will be great to have your feedback on it.

Posted by guest on November 25, 2013 at 02:12 AM PST #

Hi,

What is the editor or application you are using to create a new Angular JS project? Will that automatically create all the necessary structure as per the predefined template? Currently i am using sublime as my editor. Do you suggest me any more efficient editor for working with Angular JS?

Posted by guest on January 10, 2014 at 11:57 PM PST #

Yes, NetBeans IDE is more efficient at working with AngularJS than Sublime. It creates all the necessary structures per defined templates. Download it for free here: netbeans.org/downloads

Posted by Geertjan on January 11, 2014 at 02:59 AM PST #

Hi,

Im using Netbeans 8.0 beta and have a AngularJS project. My OS is Windows 7. With grunt all is ok, but when I try to start the karma test runner I got this error in the IDE log:

INFO [org.netbeans.api.extexecution.ExecutionService]
java.io.IOException: CreateProcess error=193, %1 ist keine zulässige Win32-Anwendung
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:385)
at java.lang.ProcessImpl.start(ProcessImpl.java:136)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)
Caused: java.io.IOException: Cannot run program "C:\myApp\node_modules\karma\bin\karma" (in directory "C:\myApp"): CreateProcess error=193, %1 ist keine zulässige Win32-Anwendung
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at org.netbeans.api.extexecution.ExternalProcessBuilder.call(ExternalProcessBuilder.java:296)
at org.netbeans.api.extexecution.ExternalProcessBuilder.call(ExternalProcessBuilder.java:78)
[catch] at org.netbeans.api.extexecution.ExecutionService$3.call(ExecutionService.java:258)
at org.netbeans.api.extexecution.ExecutionService$3.call(ExecutionService.java:234)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1423)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)

it means its not a valid win32 application...

Any solutions or is there a bug ticket for it?

Posted by guest on January 21, 2014 at 01:47 AM PST #

I am also getting the same error. Any solution on this error yet?

Posted by guest on March 16, 2014 at 08:39 AM PDT #

Hi,

I am getting same error on WIN7 with Netbeans IDE.

Any solutions on this yet?

Posted by Vik on March 16, 2014 at 08:40 AM PDT #

Are you sure you are using NetBeans IDE 8.0 RC 1?

Posted by Geertjan on March 16, 2014 at 09:38 AM PDT #

Of course, now Im using Netbeans 8.0 and not the RC1 anymore and the same problem still exists. I found this ticket: https://netbeans.org/bugzilla/show_bug.cgi?id=238346

but I only have the karma file and not a karma.cmd file.

Regards

Chris

Posted by ChrisLE on March 21, 2014 at 05:52 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today