Marcin Erdmann

Groovy, Grails, Geb...

Functional testing of Gae(lyk) applications with Geb

Thanks to the addition of gaeFunctionalTest task in version 0.7 of gradle-gae-plugin it is now extremely easy to set up Geb functional tests for GAE and Gaelyk applications. All of the following will soon be a part of the Gaelyk template project (when 1.2 is released) but for plain GAE applications following are the steps to achieve it:

  1. Apply Groovy plugin to your project as you will be writing your tests (specifications to be precise) in Groovy using Spock.

    apply plugin: 'groovy'
    
  2. Add depenendencies on Groovy, Spock, Geb and a WebDriver implementation (for example for Firefox).

    dependencies {
        groovy 'org.codehaus.groovy:groovy-all:1.8.6'
        functionalTestCompile 'org.spockframework:spock-core:0.6-groovy-1.8', {
                exclude group: 'org.codehaus.groovy', module: 'groovy-all'
            }
        functionalTestCompile 'org.codehaus.geb:geb-spock:0.7.0',
            'org.seleniumhq.selenium:selenium-firefox-driver:2.20.0'
    }
    
  3. Create src/functionalTest/groovy directory and put your specifications in it (see Geb docs for examples).

  4. Apply gradle-gae-geb-plugin so that Geb's baseUrl configuration property is set based on the gradle-gae-plugin conventions of your build:

    apply plugin: 'gae-geb'
    
    
    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'org.gradle.api.plugins:gradle-gae-geb-plugin:0.2'
        }
    }
    

Now you can simply run your functional tests by executing:

gradlew gaeFunctionalTest

Two more things to note:

  • check task now depends on gaeFunctionalTest so if you want to run all of your tests (both functional and unit) you can simply call gradle check. It also means that when running gradle build your functional tests will be executed as well.
  • all of your new your dependencies and new source set will be added to your IntelliJ project if only you run gradle idea command. Thanks to that you can easily run the tests directly from your IDE - simply start the development server first (gradle gaeRun) and then execute the tests.