Grails by default ships with support for writing functional tests using the . To create a functional test you can use the command which will create a new functional test:

    The above command will create a new Spock spec called MyFunctionalSpec.groovy in the src/integration-test/groovy directory. The test is annotated with the Integration annotation to indicate it is an integration test and extends the GebSpec super class:

    Note that the application is only loaded once for the entire test run, so functional tests share the state of the application across the whole suite.

    In addition the application is loaded in the JVM as the test, this means that the test has full access to the application state and can interact directly with data services such as GORM to setup and cleanup test data.

    If the applicationClass is not specified then the test runtime environment will attempt to locate the application class dynamically which can be problematic in multiproject builds where multiple application classes may be present.

    When running the server port by default will be randomly assigned. The Integration annotation adds a property of to the test class that you can use if you want to know what port the application is running on this isn’t needed if you are extending the GebSpec as shown above but can be useful information.