I am testing a service which is using config attributes and concatenates it to a string, like that:
GrailsConfig.config.test.directory + System.getProperty('file.separator')
+ <filename>
When runnin开发者_Go百科g the test for the above method containing the above code I receive the following error:
groovy.lang.MissingMethodException: No signature of method:
groovy.util.ConfigObject.plus() is applicable for argument types:
(java.lang.String) values: [\]
Why is the plus operator not available in my integration (or unit) test?!
Any help appreciated
Jonas
This is the error that you see when you haven't defined a config variable. You've probably defined the test.directory
in another environment, but not the test
environment.
In a unit test, you should be using mockConfig as Don's answer suggests, but in an integration test, you can use the grails configuration framework just as you would when running the app.
I guess GrailsConfig.config.test.directory
should return a String, but it's returning a ConfigObject
instead (which doesn't overload the + operator). I've never tried using GrailsConfig
in an integration test, so I don't know if this code is expected to work.
A better approach might be to mock the configuration values using mockConfig instead.
Ok, I found the issue... All String attributes must be in quotes when using mockConfig
which is not the case in out config properties file.
精彩评论