Automating the test cases

We start the server programmatically. For this, we have decided to use a Grizzly (https://javaee.github.io/grizzly/), which allows us to start the server using the configuration from Jersey's ResourceConfig (FQCN: org.glassfish.jersey.server.ResourceConfig), as shown in the test BooksEndpointTest (fragment).

The code can be found at https://bitbucket.org/vfarcic/tdd-java-alexandria:

public class BooksEndpointTest { public static final URI FULL_PATH = URI.create("http://localhost:8080/alexandria"); private HttpServer server; @Before public void setUp() throws IOException { ResourceConfig resourceConfig = new MyApplication(); server = GrizzlyHttpServerFactory .createHttpServer(FULL_PATH, resourceConfig); server.start(); ...

Get Test-Driven Java Development - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.