Sonatype Blog: Latest Posts

On the Web: Testing Javascript with Apache Maven

A few years ago Javascript was still something of a curiosity for most web developers. Fast forward to 2010, and most web applications are using liberal amounts of Javascript to take advantage of AJAX interactions and REST services. Once a curiosity, Javascript is now a primary artifact in a web project.

While adding a new feature to RESTEasy — the generation of JavaScript skeleton code to invoke RESTful web services implemented in JAX-RS — I candidly proceeded to write unit tests for that part. Unit testing this new feature meant making sure that not only was the JavaScript code produced by the web services (in our case, produced by a Servlet, and thus running in a Servlet container), I also wanted to make sure that the JavaScript code was valid, contained all the functions required and that the functions worked. Since the generated functions use AJAX to call the web services, that leaves us with the following constraints on what we need in order to test this: