Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run grails functional test without having embedded tomcat start

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

like image 401
Menelaos Avatar asked May 20 '26 15:05

Menelaos


1 Answers

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.

like image 85
eidolon1138 Avatar answered May 23 '26 09:05

eidolon1138