Java Reference
In-Depth Information
assertEquals("It works", result);
}
@AfterClass
public static void
tearDown() {
//Empty
}
private class
TestGetContentOkHandler
extends
AbstractHandler {
//Listing 6.4 here.
}
}
The test class has become quite simple. The
@BeforeClass
setUp
method constructs
the
Server
object the same way as in listing 6.2. Then come the
@Test
methods, and
we leave our
@AfterClass
method empty intentionally because we programmed the
server to stop at shutdown.
If you run the test in Eclipse, you'll see the result in figure 6.4—our test passes.
So far, so good—our tests have been testing the good side of our code. But it seems
logical to test the behavior of what would happen if the server crashed or the applica-
tion deployed in the server crashed. The next section answers exactly those questions.
Figure 6.4 Result of the first working test using a Jetty stub. JUnit starts the server before
the first test, and the server shuts itself down after the last test.