Supose the following example:
You need to obtain the facebook url from the Config.groovy
environments {
production {
grails.facebookURL = "http://www.facebook.url"
}
}
You have a controller groovy class:
And you want to build its respective unit test:
// URLController.groovy public class UrlController{ public String getFacebookUrl(){ return ConfigurationHolder.config.grails.facebookURL; } }
And you want to build its respective unit test:
// URLControllerTests.groovy public class UrlControllerTests extends GrailsUnitTestCase{ def urlController; public void setUp(){ super.setUp(); urlController = new UrlController(); } public void test_getFacebookURL(){ //Mock configurationholder like this ConfigurationHolder.config = [ grails: [facebookURL: 'http://www.facebook.com'] ]; assertEquals("http://www.facebook.com",urlController.getFacebookUrl()); } }
Voila!
jaja piola, es simple la cosa :)
ResponderEliminarlo compartí en twitter ya ;)