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

Dark Mode für Firefox und Thunderbird

Video Thumbnails unter Windows erstellen

Eindrücke aus Red Dead Redemption 2

Neuer Bluray Player: PS4

How to hardware reset the new Oura ring

Neuer Monitor: Dell S2716DG

Ein paar Bilder

Endlich da: Mein Oura Ring

Quick changelog with git

Pik Ass in Destiny 2