Fork me on GitHub

6 Feb 2011

Running Geb tests from your IDE

A frequent complaint about functional testing in Grails is that the start up / shut down cycle time of the app makes prototyping a functional test prohibitive. There has been some recent progress in this are with Luke Daley's Functional test development plugin but it would be really nice to be able to just run functional tests from inside your IDE in the same way as a similar unit test.

With Geb and IntelliJ Idea at least this is actually pretty straightforward (I'm sure the same thing is possible with Eclipse/STS I'm just not familiar enough with it).

Geb's dependence on the Grails lifecycle is pretty minimal so the tests can run without needing any magic to happen in any _Events scripts (unlike the Selenium RC plugin where this would be significantly more difficult). One extra step is required; the Grails Geb plugin normally picks up its base URL from Grails configuration and the test will not be running in the same JVM as the Grails app if it runs from the IDE so configuration will not be available. Just add the following method to your test that extends GebTests or GebSpec (or add it to a base class):

@Override String getBaseUrl() {
    super.baseUrl ?: "http://localhost:8080"
Now Geb will use the Grails configured base URL if it is in the same JVM as the app or default to http://localhost:8080 otherwise (obviously you need to change that default if that's not the host or port where your app runs).

You can then just run up the app from the command line, open the test in IntelliJ and hit Ctrl + Shift + F10 to run it. When the test completes the app is still running so you can make changes & run again with minimal turnaround time. Since the app is running in development mode you can make application changes without a server restart as well.

IntelliJ Idea's test integration is pretty good and it even groks Spock specifications. You can also debug and step through the test. The only downside is that you can't directly access domain classes or other application components in the test as they are only available from the app's JVM.


Stefan Armbruster said...

Is there any special configuration in Intellij required? I followed your setup. When using Ctrl+Shift+F10 the functional spock test class is being run 'internally' just like a normal unit test (aka inside the IDE and not via grails test-app).
The 'Run' option in the context menu does not have any further selection to the test inside the IDE or via grails test-app. This behaviour seems to be the same for all spock tests.
Any hints?


Rob said...

That's how I'm running the tests. It doesn't go through test-app which is why the baseUrl needs to be set.

Stefan Armbruster said...

I've fired up grails develop-functional-test and try to run the Spock-Geb test inside Intellij using Crtl+Shift+F10. This results in a stacktrace inside the testrunner window with an IncompatibleClassChangeError. See full stacktrace at

Rob said...

Hmm. I've not seen that before. Are IntelliJ's module dependencies in sync with Grails?

Leo said...
This comment has been removed by the author.
Leo said...
This comment has been removed by the author.
Donovan said...
This comment has been removed by the author.
Donovan said...

I tried this and it didn't work for me but pointed me in the right direction.

In Geb 0.6.0 neither GebSpec nor GebTest have a getBaseUrl() method. Instead they both have an internal browser object from which they get the baseUrl.

As such you have to set the baseUrl property of the browser instance from within your test. You will need to do this for every test so it makes sense to put it in the setup fixture method:

def setup() {
if (!browser.baseUrl) {
browser.baseUrl = "http://localhost:8080//"

Donovan said...

My URL keeps getting messed up, but basically it's localhost + the app name followed by a slash.

Unknown said...

My soul is not satisfied that it hike81ai has lost her.My sight tries to find her
as though to bring her closer.
Cheap Snapback Hats
Snapback Hats Wholesale
Cheap New Era Hats
Wholesale Hats
New Era Fitted Hats
Cheap MLB Hats
Cheap NBA Hats
monster energy hats
Red Bull Hats
Superman Hats

Unknown said...

Your article has helped me a lot, I need it
girl go game ,
cool math games ,
friv 4 ,
friv 2 ,
unblocked games happy wheels ,
juegos de autos de carrera ,
pou online ,
kizi 2 ,
juegos los simpson ,
kids games online ,
unblocked games happy wheels

Unknown said...

Thank you for such a sweet tutorial - all this time later, I've found it and love the end result. I appreciate the time you spent sharing your skills.
Geometry Dash 2.0 | Papa Louie 2|Trollface Quest 2|Dr Driving| Sonic Dash |Square Quick | Monster High Games |

Unknown said...

Thanks for sharing the information. It is very useful for my future. keep sharing
Agario , agar io,,agar,agario game,

Unknown said...

You’ve written nice post, I am gonna bookmark this page, thanks for info. I actually appreciate your own position and I will be sure to come back here.
messenger indir | messenger indir | messenger | messenger download | messenger indir | messenger indir | messenger | messenger indir

Unknown said...

I agree with you.This post is truly inspiring.
I like your post and everything you share with us is current and very informative,
I want to bookmark the page so I can return here from you that you have done a fantastic job


WinAVI Video Converter 11.5 Keygen
Trend Micro Antivirus
Movie Converter 7 Keygen
Neuratron Audio Score Ultimate Keygen

Linda Rose said...

Great post,Thanks for providing us this great knowledge,Keep it up.
Baixar Facebook | whatsapp baixar | Facebook Baixar | Baixar Facebook Gratis
|baixar whatsapp | baixar whatsapp gratis
|Traffic Rider | Traffic Rider Jogo | Traffic Rider Baixar
|Facebook Lite | Baixar Facebook Lite |

Unknown said...

This is a great article. It gave me a lot of useful information. thank you very much. Can you play more games at :
crosswords puzzles | dream league soccer apk | dream league soccer | crossword puzzles game | crosswords puzzles | dream league soccer | crossword puzzles

devikamahajan said...

IoT Consulting
IoT Mobile Apps
IoT Solution and Services

Unknown said...

New Year is the best event for everyone so celebrate this New Year 2017 with us and send some wonderful and awesome New Year Wishes, Greeting, Quotes and many more for your Love ones.
New Year Wishes 2017
Best Wishes 2017
New Year Wishes 2017

Unknown said...

happy promise day 2017
valentines day week list 2017
happy holi quotes
happy mothers day wallpapers
2017 happy holi wishes 2017
happy mothers day images 2017valentines day fab

Unknown said...

Today, we're examining the "effective age" numbers for this season's top NBA teams. Effective age is a metric used by ESPN Insider Kevin Pelton to measure a team's average age, but weighted by minutes played, rather than a straight average (which artificially inflates the average number for a team like New York, for example, if senior citizens like Marcus Camby (38) and Kurt Thomas (40) are given the same weight as heavy-minutes players such as Carmelo Anthony, J.R. Smith and Ray Felton (all under 30)).
happy holi greetings
happy mothers day images
happy holi wishes images
valentines day quotes

Unknown said...

teddy day images
hug day images2017
kiss day images2017
chocolate day quotes2017
teddy day wishes2017
hug day wishes2017
kiss day wallpapers2017
chocolate day wallpapers2017
teddy day quotes2017
hug day quotes2017
kiss day quotes2017
chocolate day images2017

buyket said...

هل تبحث عن شركة تقدم خدمات متكامله وشامله في عملية تنظيف المنازل وتشمل خدماتها تنظيف كل ما يتعلق بالمنزل من تنظيف شقق وتنظيف مجالس وموكيت وكل شيء وفي نفس الوقت يمكنها تنظيف الخزانات وتعقيمها نعم نحن نوفر لك ذلك من خلال خدماتنا التاليه
شركة مكافحة حشرات بجدة
شركة تنظيف خزانات بجدة
شركة تنظيف بجدة
شركة نقل اثاث بجدة
ليس ذلك فقط بل وايضا نوفر لك خدمات النقل المختلفه مع الفك والتركيب بافضل الفنيين وامهر العماله المتخصصه وايضا وفرنا لك خدمات النقل بين المدن المختلف بل ويتوافر لدينا قسم اضافي خاص بمكافحة الحشرات والقضاء علي مع الضمان علي عدم ظهورها مره اخري

Unknown said...

Rõ ràng, sinh viên hiện nay ý thức rất rõ vai trò quan trọng của hai môn “chìa khóa” này. Tuy nhiên, không ít các tân cử nhân vẫn sớm bị loại khỏi các cuộc tuyển dụng chỉ vì vốn tiếng Anh nghèo nàn và kỹ năng tin học yếu. Hãy cùng chúng tôi xây dựng một nền tảng tốt cho sinh viên có vốn tiếng anh và giỏi tin học khi xin việc.
đào tạo chứng chỉ tiếng anh bậc 2
chứng chỉ tiếng anh A2 đại học sư phạm hà nội
giáo dục truyền thông đại việt,
địa chỉ học tin uy tín ở hà nội
đào tạo chứng chỉ tiếng anh bậc 2

mark james said...

Happy new year 2018 wallpapers

khalid khan said...

This is a great test blog! I personally love it and find that it

happy valentines day 2018 wishes

Anonymous said...

mx player for windows 8

Anonymous said...

Great night. Thanks for sharing such a great article.

valentines day quotes for wife
valentines day quotes for her

Have a nice day.

15987 said...

20+ Happy Valentines Day Cover Pictures for Facebook
Happy Valentines Day 2019 SMS Wishes
ipl 2019 schedule: 2019 Indian Premier League Updates
Best Hacker Movies To Watch In 2019

Vital said...

galore tube

iSAi said...

Worldfree4u Movie Download Site | Punjabi Movies & Dual Audio

iSAi said...

latest hd punjabi movies 2019 download
new year 2020 images

Unknown said...

tamilRockers 2019 tamilRockers an internet portal which shares copyrighted movies and videos right from the Indian Film Industry. This site leaks almost all Indian movies of languages Telugu, Tamil, Hindi, Malayalam, and etc. This site is well known for its regular updates with the films and piracy.

In some countries, people like to celebrate this amazing day with their friends and family while some of them like to celebrate it with their partners. We think that Happy New Year 2020 Images, Happy New Year 2020 Wallpapers, & Happy New Year 2020 Quotes and other things are here for you all. You all can get the whole updates about the Happy New Year cards along with the schedule of your country. Now the fact is, we all are looking for the best wishes, quotes, SMS, Sayings, and One-liners to impress our family & friends, and we provided all this free content for you here.

Rexoxer. is one of the leading new publishing sites in India. We aimed in helping people get the latest breaking news in a better way. Rexoxer. is the source for latest breaking news all across India. One can find all the news stull related to Bollywood, tech, business, politics and much more. Stay updated with Rexoxer.

Rita said...

hd tube videos

John said...

Ensure you check them consistently, as when finished you'll gain Satisfaction Points, which would then be able to be spent on extraordinary elixirs to help your Sims.
Get latest the sims 4 perk points cheats 2019

Herbal Dawakhana said...

Love To See This Such a Wonderful Information Admin Keep It Up Herbal Medicine Company

Unknown said...

replica bags in london replica bags and shoes best replica bags online 2018