3

I have a project that I am usually debugging/running using the grails run-app command. I would like to run a test but without having the server run again only for the specific test.

I usually run the server in debug mode all the time in the background.

I've tried playing around with the run configurations in iteli-j, with latest try being grails test-app functional: className

Menelaos
  • 23,508
  • 18
  • 90
  • 155

2 Answers2

4

In Grails 2.4.4 if you override the baseUrl you can run your tests against a server other than localhost. For example, we have a pre-production server hosted on AWS and we run a subset of our functional tests against it from Jenkins, post-deploy, as a smoke test.

grails -plain-output test-app -baseUrl=https://foo.bar.org/ -echoOut -echoErr functional:

That works, but test-app still starts the embedded tomcat server. However, with a bit of digging, I found that overriding the server host to point to a running instance will cause the tests to run without starting the embedded tomcat. There are a couple of ways to accomplish this:

Pass the value on the command line:

grails -plain-output test-app -Dgrails.server.host=foo.bar.org -baseUrl=https://foo.bar.org/ -echoOut -echoErr functional:

Or, overriding the value in Config.groovy for the specific environment should also work:

...
preProd {
    ...
    grails.server.host = 'foo.bar.org'
    ...
}
...

It isn't documented under test-app, but it is mentioned under run-app and it turns out it works for test-app too.

This works because Grails determines if the embedded server should be started by trying to open a connection to the server host/port, and if successful skips the startup.

From trial and error I have discovered that I have the best results when I specify both grails.server.host and -baseUrl even though the base url becomes redundant information. Possibly this is because my case involves an ssl connection, but I tried running with -https instead of -baseUrl=... and the tests just hung.

eidolon1138
  • 434
  • 5
  • 9
1

This plugin maybe helps you.

Grails functional-test-development Plugin

This plugin aims to make developing functional tests for Grails more convenient by facilitating running your tests against an already running application. It utilises the improved functional testing support added in Grails 1.3.5 and does not work with earlier versions.

ricardogobbo
  • 1,690
  • 3
  • 19
  • 41