Gretty supports integration tests in the following way: it can start servlet-container before and stop after the specified task. The task itself can perform arbitrary tests (for example, use Geb and Spock for testing client-side functionality direct in the browser).


gretty {
  // ...
  integrationTestTask = 'integrationTest' // name of existing gradle task
  // ...


When you run gradle integrationTest from command-line, Gretty starts servlet-container before integrationTest task and stops it after.

Gretty does not define integration test task nor does it augment it in any way. All it does is start and stop servlet-container.

Tunneling properties to test code

When your integration task supports JavaForkOptions interface (for example, when integration task is instance of Test class), Gretty passes the following system properties to the java process of integration task:

Property Content/Purpose


The context path of the current web-app project


Currently used HTTP port, when HTTP protocol is enabled; null otherwise.


same as httpPort


"http://${host}:${httpPort}${contextPath}", when HTTP protocol is enabled; null otherwise.


same as gretty.httpBaseURI


Currently used HTTPS port, when HTTPS protocol is enabled; null otherwise.


"http://${host}:${httpsPort}${contextPath}", when HTTPS protocol is enabled; null otherwise.

Your test code can access these properties via System.getProperty function. This allows to parametrize test code with Gretty-specific parameters.