Grails productivity enhancer. The unsung hero ‘grails interactive mode’

30 / Nov / 2011 by Mohd Farid 1 comments

Of late, I have been thinking about the popularity of grails interactive mode amongst developers. I found that though most of us are aware of this mode but we don’t use it as often, as it should be.

Where should I use grails –interactive mode while developing in grails?
The answer may vary from person to person and the level of expertise. For me, I found it amazing while running my tests and creating artifacts.

I shall describe the advantages that I found with interactive mode while running Unit Tests. Let us take an example here:

I have a class called PersonUtil which needs to be unit tested. I write a PersonUtilTests class for testing its functionality. In order to run this particular unit test, I can use the following command:

grails test-app unit: PersonUtilTests

This takes approximately 20 secs on an average to run on my machine with a decent configuration.

Alternatively, We can run it in interactive mode. What we need to do is

grails –interactive

This shall bring the grails infrastructure up and make it just ready to run commands. It takes around 5 seconds.

Welcome to Grails 1.3.7 – http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /opt/grails

Base Directory: /home/farid/grailsApplications/survey-app/ErServices
——————————————————–
Interactive mode ready. Enter a Grails command or type “exit” to quit interactive mode (hit ENTER to run the last command):

Now, to test the app I can use the following command:

——————————————————-
Command TestApp completed in 2461ms
——————————————————–
Interactive mode ready. Enter a Grails command or type “exit” to quit interactive mode (hit ENTER to run the last command):
test-app unit: PersonUtilTests

It took 15 seconds to run this for first time.
For subsequent runs, it took 2-4 seconds. Which is a clear advantage of 16 seconds for every run. These 16 seconds are no less than gem when you are in your “flow-state”( in concentration mode).

While development, we make frequent changes to our code and therefore we need to run our unit tests multiple times. Every time I make a change and re run my unit test it takes 20 seconds through conventional grails test-app whereas it takes 3-4 seconds through interactive mode.

Earlier, I used to get frustrated while waiting for test cases to execute. This waiting time is one of the biggest factor that drives us from doing Test Driven Development.

Just in case you have not tried it. Please give it a shot. Believe me, it’s worth trying, you wont be disappointed!!!

FOUND THIS USEFUL? SHARE IT

comments (1 “Grails productivity enhancer. The unsung hero ‘grails interactive mode’”)

  1. Burt Beckwith

    Note that in 2.0 to get into interactive mode you just run ‘grails’ instead of ‘grails interactive’ like in 1.3 and earlier.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *