O'Reilly logo

Test-Driven Java Development - Second Edition by Viktor Farcic, Alex Garcia

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required