O'Reilly logo

Play Framework Cookbook - Second Edition by Giancarlo Inductivo, Alexander Reelsen

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

Testing controllers

The following recipe focuses on writing a test for our controller objects. We will use a FakeApplication to create a mock HTTP request to the Product XML listing page and add assertions to validate that the response we receive is indeed an XML representing all of the products in our database. We will then use the Activator command to run our test.

How to do it...

For Java, we need to take the following steps:

  1. Edit the ProductTest.java file and add the following content:
     // add new imports import play.mvc.*; import static org.fest.assertions.Assertions.*; //add new test @Test public void testProductListAsXml() { Result result = callAction(controllers.routes.ref.Application.listProductsAsXML()); assertThat(status(result)).isEqualTo(OK); ...

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