In a previous post, I mentioned using Jetty as part of testing a web application. The basic idea is that you can embed Jetty within your application (or at least within your test code), have your tests fire it up as required, and then perform “live” queries against your site. The purists would argue, of course, that this is “integration testing” as opposed to “unit testing,” since it typically requires infrastructure around your web app (database, etc.). I won’t argue with that. I will point out, however, that this can be very useful testing since it runs your code “end to end.” Thus, it can uncover things like REST URL’s not being mapped as you expect which might not be detected if you’re testing your REST controller classes in isolation.

So here’s how I go about using an embedded Jetty for testing.