Testing and Some Plugins
Learn about testing in Grails and the cache plugin.
We'll cover the following
Testing
Grails supports unit testing with a mixin approach. Annotations:
@TestFor(X)
: Specifies the class under test.@Mock(Y)
: Creates a Mock for the given class.
For tests GORM provides an in-memory mock database that uses a ConcurrentHashMap. You can create tests for Tag libraries, command objects, URL-Mappings, XML & JSON, etc.
Cache plugin
- You can add the
@Cacheable
annotation on Service or Controller methods. - Cache tags:
cache:block
andcache:render
- Cache-ehcache, -redis, and -gemfire
- Cache configuration DSL
Grails wrapper
The Grails wrapper was added in Grails 2.0. You can create the wrapper using the following command:
$ grails wrapper
The above produces grailsw
and grailsw.bat
(for Nix and Windows, respectively).
The Grails wrapper is helpful when multiple people are working on a project. The wrapper scripts will actually download and install grails when run. Then you can send these scripts to anyone or keep them in your repository.
Cloud
Grails is supported by the following cloud providers:
- Amazon
- Heroku
Get hands-on with 1400+ tech skills courses.