在grails 2.x中编写测试用例时,从I18n属性文件获取消息时出现问题。
在 Controller 中,我正在这样使用:
g.message(code:'upload.coverpage.file.isempty.msg')
从 Controller 进入结果对象时,消息将返回为:
upload.coverpage.file.isempty.msg
但原始消息是:
"Sorry, the file size is empty."
如何获取原始消息。
任何人有主意吗?
感谢和问候
阿纳金德拉
最佳答案
我认为这是测试消息的正确方法。我现在正在为在grails 1.3.5上编写的应用程序编写测试,但 Controller 单元测试出错:
No signature of method: ChallengeListingController.message()
我决定以这种方式解决它:
ChallengeListingController.metaClass.message={def msg-> return msg.code}
我确切地返回消息代码:足以确定字符串正确,并且您当然可以将代码与值分开。
关于unit-testing - 如何使用Grails 2.x单元测试从i18n消息属性获取消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14257901/