unit-testing - 如何使用Grails 2.x单元测试从i18n消息属性获取消息?

标签 unit-testing grails internationalization message

在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/

相关文章:

angularjs - Jasmine spyOn函数和返回的对象

grails - BootStrap.groovy 中的访问 Controller 请求参数

grails - 在应用程序上下文中定位的Grails 2.5.0端点

grails - 有关网域中listsize的Grails标准

c# - 从卫星组件中获取所有支持的文化

python - 有什么方法可以像 django makemessage 一样生成 Tornado 本地化 CSV 文件吗?

spring - 如何在 Spring Framework 3 中翻译 Controller 内的文本?

c# - NUnit:在单个测试中运行多个断言

javascript - react 状态没有 Jest 更新

unit-testing - 单元测试验证器约束