Chapter 3. Testing Ratpack Applications

Now that we have covered how to build proper project structure and work with requests a little more completely, it is important to understand how to go about writing tests for your application. As a developer-first framework, Ratpack understands the need to make testing applications easy, and thus provides many test fixtures and utilities to aid in test-driven development and writing functional and integration tests.

Getting started with testing in Ratpack is as easy as including a test-scoped dependency in your project. If you are making use of the Gradle integration, then the process of adding the dependency will look very similar to how we imported framework components into the project in the previous chapter. If you are using a dependency and build management tool besides Gradle, then the ratpack-test framework module needs to be brought into the test time’s compile and runtime classpath.

When using the Gradle plugin, you can add the ratpack-test framework module through the dependencies block of your project’s build.gradle file. This time, however, it will need to add the dependency to the testCompile build configuration, so that the test fixtures are properly isolated from the regular compile and runtime classpaths. In addition to the ratpack-test module, you need to include a testing framework. Ratpack’s test fixtures do not enforce any opinions about the testing infrastructure your project uses, but the Spock Framework is the preferred ...

Get Learning Ratpack 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.