Testing internationalized applications in Grails

So, you take advantage of the internationalization support that Grails have out of the box and now you need to test your application in different languages. What can you do?

Grails tests build a mocked request instance of the type org.codehaus.groovy.grails.plugins.testing.GrailsMockHttpServletRequest, this class extends org.springframework.mock.web.MockHttpServletRequest and have the method addPreferredLocale, with that you can set the java.util.Locale that will be used when your code call g.message.

Here’s an Spock Integration Test example

About these ads

Java, Groovy & Grails developer https://docs.google.com/document/d/1AGesDYQaIEASyEasEELVeQbgZzQM1BBgkpkMNQxE2-A

Tagged with: , ,
Posted in Grails, Internacionalization
2 comments on “Testing internationalized applications in Grails
  1. stokito says:

    Also, it may be better to mention few things:
    1. request.locale never can be null
    2. request.addPreferredLocale keeps previous locales, and they are still available from request.locales.
    3. If you want to change all locales you can call request.setPreferredLocales([])

    If you looking for more examples here is one https://github.com/stokito/grails-locale-configuration-plugin/blob/master/test/unit/name/stokito/SmartConfigLocaleResolverSpec.groovy

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: