views:

80

answers:

2

I'm trying to test my grails app using integration test that makes http requests. Actually it's a selenium/tellurium test, but it doesn't matter. But as i see when i running grails tests it doesn't starts web container, the same time i see many examples in blog articles that people tests grails app using selenium and other test tools that requires http access.

I've create an empty grails app:

mvn org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-4:generate -DarchetypeGroupId=org.grails -DarchetypeArtifactId=grails-maven-archetype -DarchetypeVersion=1.3.4 -DgroupId=example -DartifactId=testportapp

cd testportapp/

mvn initialize

mvn grails:test-app

Tests PASSED - view reports in target/test-reports
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL

thats ok.

and now add an integration test that tries to connect to grails test/integration/ListenPortTest.groovy:

class ListenPortTest extends GroovyTestCase {
        void testPort(){
                def s = new Socket("localhost", 8080);
                s.close()
        }        
}

and run test again. Now we receive following exception:

Connection refused
   java.net.ConnectException: Connection refused
   ....

I've checked it also by using browser, wget and netstat, and looks like grails not started or not opened any port.

And the question: How i can configure grails to open an port when executing integration tests?

+1  A: 

I think you are looking for this plugin

http://www.grails.org/plugin/functional-test

Aaron Saunders
+4  A: 

Grails supports two types of tests by default, unit and integration, plus functional testing using a plugin. Unit and integration tests are quite similar and are really both unit tests, except that integration tests have an initialized Spring application context, Hibernate configuration, in-memory database, etc. But no running web server - you need functional tests for that.

There are several options for functional testing, the most popular ones being WebTest: http://grails.org/plugin/webtest, the Functional Testing plugin: http://grails.org/plugin/functional-test, and the Selenium RC plugin: http://grails.org/plugin/selenium-rc.

The newest one is Geb: http://grails.org/plugin/geb and if you're looking for Selenium support it's going to be your best bet. The manual is at http://geb.codehaus.org/ and there was a recent blog post written about it here: http://blog.springsource.com/2010/08/28/the-future-of-functional-web-testing/

Burt Beckwith