X

Geertjan's Blog

  • November 22, 2013

Karma: AngularJS Automated Test Runner

Geertjan Wielenga
Product Manager

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.

Join the discussion

Comments ( 11 )
  • Cuneyt Ozen Sunday, November 24, 2013

    Hi,

    Just tried NetBeans IDE Dev (Build 201311210002).

    "Karma" node does not appear.


  • guest Monday, November 25, 2013

    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.


  • guest Saturday, January 11, 2014

    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?


  • Geertjan Saturday, January 11, 2014

    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


  • guest Tuesday, January 21, 2014

    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?


  • guest Sunday, March 16, 2014

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


  • Vik Sunday, March 16, 2014

    Hi,

    I am getting same error on WIN7 with Netbeans IDE.

    Any solutions on this yet?


  • Geertjan Sunday, March 16, 2014

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


  • ChrisLE Friday, March 21, 2014

    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


  • guest Wednesday, April 23, 2014

    I too am having the same problem as others reported. Using Netbeans 8.0 on Windows 7.

    "CreateProcess error=193, %1 is not a valid Win32 application"

    and karma is located in "..\node_modules\karma\bin\karma", installed via npm.


  • Krishna Sunday, July 23, 2017
    In my project we have more than 7000 test cases which takes more than 15 minutes to execute. Is it possible to decrease time by executing test cases in parallel?
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha