Using Mortbays Jetty as embedded servlet container in unit tests


Ich habe diesen Blogeintrag in einem Firmenblog veröffentlicht, daher ist er in Englisch. Und bitte:

Today I created a simple unit test that runs Mortbays Jetty as an embedded servlet container for a unit test with JUnit 4. It's quite simple to run the ServletTester and add Servlets to it, so you can create HTTP requests and assert against the responses.

To run Jetty you need the following JAR files in your classpath:

  • jetty-6.X.Y.jar
  • jetty-servlet-tester-6.X.Y.jar
  • jetty-util-6.X.Y.jar
  • servlet-api-2.5-*.jar

The HelloServletTest simply sets up Jetty to initialize a servlet, runs one test and stops Jetty after it. The HelloServlet I used for the first test. It's the obvious Hello World example.

Now you can remove HelloServlet</code>, add your own servlet classes and go unit test them. ;-)</p>

Weitere Artikel

Crossfit Open WOD 17.5

Crossfit Open WOD 17.4

Crossfit Open WOD 17.3

Crossfit Open Workout 17.2

Crossfit Open Workout 17.1

Run Feedbin in your local Kubernetes cluster

Running Threema Web in Docker

Neues Workout Video

Diät Update #1

Workout 21.01.2017