Ratpacked: Assert No Exceptions Are Thrown With RequestFixture
Writing unit tests for our handlers in Ratpack is easy with RequestFixture
.
We invoke the handle
method and use a Handler
or Chain
we want to test as argument.
We can provide extra details on the fixture instance with a second argument, for example adding objects to the registry or setting the request method.
The handle
method returns a HandlingResult
object.
This object has the method exception
that we can use to see if an exception occurred in our code under test.
The method throws a HandlerExceptionNotThrownException
if the expected exception doesn’t occur.
In the following example we have two feature methods to check if an exception occurred or not: