public abstract class GroovyUnitTest extends Object
| Constructor and Description |
|---|
GroovyUnitTest() |
public static Invocation invoke(Handler handler, @DelegatesTo(value=InvocationBuilder.class) Closure<?> builder) throws InvocationTimeoutException
Handler.
Example:
import ratpack.handling.*
import static ratpack.groovy.test.GroovyUnitTest.invoke
class MyHandler implements Handler {
void handle(Context context) {
context.with {
def outputHeaderValue = request.headers.get("input-value") + ":bar"
response.headers.set("output-value", outputHeaderValue)
render "received: " + request.path
}
}
}
// The following code unit tests MyHandler, typically it would be written inside a test framework.
def invocation = invoke(new MyHandler()) {
header "input-value", "foo"
uri "some/path"
}
assert invocation.rendered(String) == "received: some/path"
assert invocation.headers.get("output-value") == "foo:bar"
handler - The handler to unit testbuilder - The closure that configuresInvocationTimeoutException - if the handler takes more than InvocationBuilder.timeout(int) seconds to send a response or call next() on the context