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.

58 comments:

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?

Regards,
Stefan

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 http://pastebin.com/77Aqif5t

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.

qinbincai123 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

Lan Linh said...

Do not know what to say, I liked your article and I hope you will have many entries or more.
pacman games
happy wheels demo
my little pony games
hulk games
mickey mouse games
car games
bike games
free fun games
unblocked games

Trần Lucy 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

Love KidsTV said...

Thanks for your post. Click to play Plants vs Zombies , Solitaire,Tom And Jerry Games, Brain Games, Happy Wheels , Five Nights At Freddy's

Love KidsTV said...

Truyen ngon tinh hay la the loai truyen tinh cam
Truyen teen hay la nhung truyen tinh yeu tuoi teen
Don doc tai trang doc truyen online.

Agar io 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 |

Agar io said...

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

Messenger Indir 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

Tahir Bahi 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

T H A N K S
F O R
S H A R I N G

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

Ninjago Games said...

Thank you for sharing valuable information. Nice post. I enjoyed reading this post.Can you play more games at :
ninjago game | swords and souls game | subway surfers game | goodgame big farm | strikeforce kitty 2 | agario game

Alice Denny said...

Welcomes to google underwater keep sharing such ideas in the future as well. google mirror this was actually what i was looking for,and i am glad to came here!
elgoog Hi! I’ve been reading your blog for a while google gravity I want you to thank for your time of this wonderful read!!! google terminal now and finally got the courage to go ahead and give youu a shout out from Austin Texas!
google pacman Just wanted to tell you keep up the fantastic work!my weblog: google guitar I definately enjoy every little bit of it and I have you bookmarked to check out new stuff of your blog a must read blog! google snake
Amazing insight you have on this, Happy wheels it's nice to find a website that details so much information about different artists... Age of war 2 This article always blew me... Earn to die For how many times I have read this.
slither io
slitherio
big farm

Breakout Atari said...

This is a great article. It gave me a lot of useful information. thank you very much. Can you play more games at :
red ball 4 | ninjago games | swords and souls | strike force kitty 2 | run 2 | slitherio | super smash flash 2 | atari breakout

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 |

Williams Milada 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

tanya sweet said...


First of all i am saying that i like your post very much.I am really impressed by the way in which you presented the content and also the structure of the post. Hope you can gave us more posts like this and i really appreciate your hardwork.

Valentine Week List 2017
Valentine Week List 2017
Happy New Year 2018
valentine week list
best whatsapp love status
Good night Photos
Happy Birthday Quotes
Happy New Year 2017

devikamahajan said...

IoT Consulting
IoT Mobile Apps
IoT Solution and Services

Anjali Sharma 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

rocko hunter said...

Felice Anno Nuovo

Happy new year new year 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

Aman said...



rose day images
propose day 2017
happy promise day
teddy day images
happy chocolate day

Happy new year new year 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

Event mine 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

akbar badshah said...

Valentine day Wishes
Valentine's day Wishes 2017
Valentine's day 2017
Valentine day Quotes
Valentine day Poem
Valentine day celebration with Girlfriend
Valentine's Week List 2017

94 hằng said...

Mostly people have all the same things when they are writing academic task or any other writing, especially light music most people like during the writing.
dream league soccer download , dream league soccer apk , download dream league soccer , dream league soccer

94 hằng said...

Mostly people have all the same things when they are writing academic task or any other writing, especially light music most people like during the writing.

subway surf , baixar subway surf, subway surf download , download subway surf

94 hằng said...

Life becomes more interesting and wonderful when you share your memorable moments with friends and family through unique photographs. You can create your own unique style impressed with image editing software. And after hours of work stress you can also

Square Quick
Square Quick
Square Quick
Square Quick
Square Quick

94 hằng said...

You need to have time to take care of the active. It in fact was a amusement account it. Look advanced to far added agreeable from you.

entrar hotmail agora , hotmail entrar, entrar hotmail , entrar no hotmail

94 hằng said...

Thanks I have read your article, it is very interesting and exciting
download go launcher, go launcher apk, go launcher , go launcher androi,

94 hằng said...

You need to have time to take care of the active. It in fact was a amusement account it. Look advanced to far added agreeable from you.

baixar banana kong , banana kong , download banana kong , banana kong download , banana kong

94 hằng said...

Life becomes more interesting and wonderful when you share your memorable moments with friends and family through unique photographs. You can create your own unique style impressed with image editing software. And after hours of work stress you can also

whatsapp messenger
baixar whatsapp
whatsapp plus
download whatsapp
whatsapp baixar

94 hằng said...

You need to have time to take care of the active. It in fact was a amusement account it. Look advanced to far added agreeable from you.
Hotmail
Hotmail Iniciar Sesión
Iniciar Sesión
Iniciar Sesión Hotmail
Iniciar Sesión
Iniciar Sesión Hotmail

94 hằng said...

Mostly people have all the same things when they are writing academic task or any other writing, especially light music most people like during the writing.
facebook iniciar sesión , facebook, iniciar sesion , iniciar sesion facebook

94 hằng said...

I really thank you for the valuable info on this great subject and look forward to more great posts. Thanks a lot for enjoying this beauty article with me.

geometry dash pc, geometry Dash, geometry dash lite, geometry dash play, geometry dash online

buyket said...


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



94 hằng said...

You need to have time to take care of the active. It in fact was a amusement account it. Look advanced to far added agreeable from you.

banana kong download , banana kong , baixar banana kong , download banana kong

94 hằng said...

You need to have time to take care of the active. It in fact was a amusement account it. Look advanced to far added agreeable from you.

entrar hotmail agora , hotmail entrar, entrar hotmail , entrar no hotmail

94 hằng said...

Life becomes more interesting and wonderful when you share your memorable moments with friends and family through unique photographs. You can create your own unique style impressed with image editing software. And after hours of work stress you can also

whatsapp messenger
baixar whatsapp
whatsapp plus
download whatsapp
whatsapp baixar

94 hằng said...

Mostly people have all the same things when they are writing academic task or any other writing, especially light music most people like during the writing.
dream league soccer download , dream league soccer apk , download dream league soccer , dream league soccer

94 hằng said...

Mostly people have all the same things when they are writing academic task or any other writing, especially light music most people like during the writing.

subway surf , baixar subway surf, subway surf download , download subway surf

94 hằng said...

Life becomes more interesting and wonderful when you share your memorable moments with friends and family through unique photographs. You can create your own unique style impressed with image editing software. And after hours of work stress you can also

Square Quick
Square Quick
Square Quick
Square Quick
Square Quick

94 hằng said...

I really thank you for the valuable info on this great subject and look forward to more great posts. Thanks a lot for enjoying this beauty article with me.

geometry dash pc, geometry Dash, geometry dash lite, geometry dash play, geometry dash online

94 hằng said...

You need to have time to take care of the active. It in fact was a amusement account it. Look advanced to far added agreeable from you.
Hotmail
Hotmail Iniciar Sesión
Iniciar Sesión
Iniciar Sesión Hotmail
Iniciar Sesión
Iniciar Sesión Hotmail

94 hằng said...

Mostly people have all the same things when they are writing academic task or any other writing, especially light music most people like during the writing.
facebook iniciar sesión , facebook, iniciar sesion , iniciar sesion facebook

khizi said...

Get all the news about champion trophy live score ball by ball commentary and complete highlights of champion trophy 2017.
champion trophy 2017 live match
champion trophy 2017 live streaming
champion trophy 2017 live matches

ngocanh said...

Your blog posts are more interesting and impressive. I think there are many people like and visit it regularly, including me.I actually appreciate your own position and I will be sure to come back here.
b612 l b612 app l baixar b612 l download b612 l b612 apk

Unknown said...

Interesting article! Thank you for sharing them! I hope you will continue to have similar posts to share with everyone!
happy wheels

agario games said...

Thanks for your post! I believe there are many who feel the same satisfaction as I read this article! I hope you will continue to have such articles to share with everyone!
abcya

agario games said...

Thanks for your post! I believe there are many who feel the same satisfaction as I read this article! I hope you will continue to have such articles to share with everyone!
slither io

truyen thong dai viet giao duc 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