Skip to content

Latest commit

 

History

History
58 lines (39 loc) · 1.72 KB

README.md

File metadata and controls

58 lines (39 loc) · 1.72 KB

Grails Functional Test Suite v2

New version of the functional test suite for Grails based on Gradle, Spock and Geb.

Tests are found within the src/test/groovy directory.

A basic test looks like:

class RunAppSpec extends BaseSpec {
    void "Test run-app starts correctly"() {
        given:"A new project"
            grails {
                createApp "test"
                runApp()
            }
        
        when:"The home page is requested"
            go ""
        then:"The Grails welcome page is shown"
            title == "Welcome to Grails"
    }
}

The above example creates a new project and tests it, deleting it on completion. To test an existing project you can instead use BaseApplicationSpec:

class RunAppSpec extends BaseApplicationSpec {
	String getApplication() { "foo" }
	void "Test run-app starts correctly"() {
        when:"The home page is requested"
            go ""
        then:"The Grails welcome page is shown"
            title == "Welcome to Grails"			
	}
}

The application needs to be created in the "apps" directory of the project before this test can be run.

Tests are executed using standard Gradle test command:

./gradlew test

Running a single test can be done with:

./gradlew -Dtest.single=RunApp test

Where "RunApp" above is the test name.

By default the test suite tries to look for GRAILS_HOME in the directories ../grails-core or ../grails-master. If you prefer to tell the suite where Grails is you can do:

./gradlew -Dgrails.home=/path/to/grails test

Tests can also be run from the IDE. Just generate Eclipse or Intellij project files:

./gradlew eclipse
./gradlew idea

Import the project into your IDE and run the specs directly.