Grails application with AngularJS: Karma with test-app – Part 3

In Part 2, we added karma test runner to our AnGrails application. Its great that you can test your javascripts on the fly locally. What about testing it as part of your grails test-app lifecycle ?

Step: Setup JUnit/Karma integration so that karma can run via grails test-app

Edit BuildConfig.groovy

Add the following line under plugins

test ':karma-test-runner:0.2.0'

See karma-test-runner grails plugin for more information.

Create new file c:/projects/angrails/test/unit/angrails/

Add the following text:

package angrails;
import de.is24.util.karmatestrunner.junit.KarmaTestSuiteRunner;
import org.junit.runner.RunWith;
public class JavaScriptUnitTestKarmaSuite {

Run the test.

cmd> grails test-app

| Compiling 1 source files.....
Karma will be started with process builder args: [karma.cmd, start, C:\projects\angrails\.\test\javascript\config\karma.conf.js]
| Running 1 javascript test...
Starting karma result receiver server on localhost:9889
Warning: Native modules not compiled. XOR performance will be degraded.
INFO [karma]: Karma v0.10.9 server started at http://localhost:8001/
Warning: Native modules not compiled. UTF-8 validation disabled.
INFO [launcher]: Starting browser Chrome
INFO [Chrome 33.0.1750 (Windows 7)]: Connected on socket yX5XSRbnYl_IzwQp7ocG
LOG: 'angrails manifest load complete.'
LOG: 'calling'
Chrome 33.0.1750 (Windows 7): Executed 1 of 1 SUCCESS (0.248 secs / 0.03 secs)


If one of the following errors occur:

Could not load class in test type ‘javascript’
ERROR [karma]: { [Error: listen EACCES] code: ‘EACCES’, errno: ‘EACCES’, syscall: ‘listen’ }

There is some issue with how the karma is being started via test-app. I found both cmd line grails test-app and invoking via IntelliJ grails cmd window (Alt+G) yield different results. The common problem of both errors seems to be the port number that karma starts on.


1. Change the port number in karma.conf.js to 8001 or try another number (above 1024 and available).
2. Remove line of the port number specified in @KarmaTestSuiteRunner.KarmaRemoteServerPort(8001)


With the above settings (ie karma.conf.js:port = 8001 and no port specified in the java code), the test-app works fine in both IntelliJ and command line.

During your test runs, sometimes the port binding is not released when test is shutdown. On *nix systems, you can just use kill <process-id>. For Windows, use PowerShell and do the following:

netstat -o -n -a | findstr "<portnumber>"
stop-process -Id <pid>

In Part 3, we saw how to add karma to grails test-app lifecycle.
In Part 4, lets see how to get karma tests running on your build server.

6 thoughts on “Grails application with AngularJS: Karma with test-app – Part 3

  1. Hi vasya,
    I’m following your tutorial to make a first grails app with angularJs as frontend framework.

    I run the test succesfully with command “karma start karma.conf.js” but I’m facing this problem when I run test with command “grails test-app”.

    | Running without daemon…
    | Error Error loading event script from file [/media/Data/Users/Simone/Projects/Grails/MyRecipes/target/work/plugins/asset-pipeline-1.6.1/scripts/_Events.groovy] No such property: assetPipelinePluginDir for class: _Events (Use –stacktrace to see the full trace)
    | Running Grails application
    | Server running. Browse to http://localhost:8080/MyRecipes
    | Waiting for server availablility
    | Waiting for server availablility.
    | Waiting for server availablility..
    | Waiting for server availablility…
    | Waiting for server availablility….
    | Waiting for server availablility…..
    | Server stopped
    | Tests PASSED – view reports in /media/Data/Users/Simone/Projects/Grails/MyRecipes/target/test-reports

    I installed karma-test-runner:0.2.0 as Karma plugin for Grails at version 2.3.7

    Could be an incompatibility between asset-pipeline:1.6.1 and karma-test-runner:0.2.0 plugins?



  2. @Simone, i have seen the “No such property” in some scenarios. Can you try the following:

    1. does the error happen if you run test-app within an ide? (IDEA or Eclipse)?
    2. can you delete your target/* and do a refresh-dependencies and then test-app?
    3. you can also try updating to latest asset-pipeline which is at 1.8.1
    4. in one of my earlier versions, a similar problem existed while using clover plugin – i commented out the clover plugin in buildconfig to avoid this error
    5. after excluding resources and including asset-pipeline in buildconfig, did you do a refresh-dependencies ?


  3. Hi Vasya.

    I have set up every thing accordingly and refreshed dependencies multiple times.
    But getting the following error. can you please

    Starting karma result receiver server on localhost:8001
    | Failure: angrails.JavaScriptUnitTestKarmaSuite
    | java.lang.NoClassDefFoundError: org/eclipse/jetty/server/Server
    at java.lang.ClassLoader.defineClass(
    at java.lang.ClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    at de.is24.util.karmatestrunner.JSTestExecutionServer.beforeTests(
    at de.is24.util.karmatestrunner.junit.KarmaTestSuiteRunner$3.evaluate(
    at de.is24.util.karmatestrunner.junit.KarmaTestSuiteRunner$2.evaluate(
    at org.junit.runners.Suite.runChild(
    at org.junit.runners.Suite.runChild(
    at org.junit.runners.ParentRunner$
    at org.junit.runners.ParentRunner$1.schedule(
    at org.junit.runners.ParentRunner.runChildren(
    at org.junit.runners.ParentRunner.access$000(
    at org.junit.runners.ParentRunner$2.evaluate(
    Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.server.Server
    at java.lang.ClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    … 22 more
    | Completed 0 javascript test, 1 failed in 0m 0s


  4. Hi,

    I got the FAILED result when I do grails test-app unit:javascript. I setup a new project with just 1 sample test from your example. Any comment?

    | Running 1 javascript test…
    Starting karma result receiver server on localhost:9889
    INFO [karma]: Karma v0.12.16 server started at http://localhost:9876/
    INFO [launcher]: Starting browser PhantomJS
    INFO [PhantomJS 1.9.7 (Mac OS X)]: Connected on socket lDRjk7SIG3fQ3Dq_O2ZA with id 86099453
    PhantomJS 1.9.7 (Mac OS X) LOG: ‘angrails manifest load complete.’

    PhantomJS 1.9.7 (Mac OS X): Executed 1 of 1 SUCCESS (0.004 secs / 0.013 secs)
    Program terminated!
    | Completed 0 javascript test, 1 failed in 0m 2s
    | Tests FAILED – view reports in


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s