Grails UnitTesting & Deployment

Unit Testing
GrailsUnitTestCase and GroovyTestCase both extend JUnit 3.x TestCase.MVC Unit Test case will extend GrailsUNitTest case and delegate the test case control to ControllerUnitTestCase and TagLibUnitTestCase

UNit TestGrailsUnitTestCase and its offspring offer mock services that replicate the services available in integration tests, without incurring the overhead of running the real services. A GrailsUnitTestCase makes three convenience methods available: mockForConstraintsTests(), mockDomain(), and mockLogging(). Normally you would have to create an integration test to write assertions against this functionality. And you still can, if you’d like. But knowing that unit tests run much faster than integration tests, it’s nice to be able to mock this behavior out.

Import grails.test.*
Class UserTests extends GrailsUnitTestCase {
Void testsimpleConstraints {
Def user = new User ( login: “someone”, password: “xxx”, role :”admin”)
assertFals user.validate()

For example, suppose that you’d like to test the validation on the User class.


We can easily generate a WAR file and deploy it to Tomcat, JBoss, GlassFish, or the application server of your choice Command “grails clean” will clean and to make sure that there aren’t any lingering development-mode artifacts hanging around. After clean command execute grails war . You should end up with a genuine JEE WAR file, suitable for deploying to any Java application server

$ grails war

Done creating WAR

No additional server configuration is necessary to deploy your WAR – it includes the Groovy JAR, the Grails supporting JARs, and everything else that you added to the lib directory.


Grails’s main target is to develop web application quickly and rapidly in agile manner. Grails is based on Convention over configuration and DRY(Don’t Repeat yourself) and not only that we can re use existing java code in Grails that give power to build robust and stable web application in quickly and rapid manner. This paper explained the usage and best practices around the Groovy and Grails.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s