Grails 集成测试:get 的问题
我正在尝试编写一个简单的集成测试,但在使用域对象时遇到了一些问题。我读过 单元测试 但不能弄清楚。
这是我的简单测试:
User user = User.get(1)
controller.params.userid = "1"
controller.session.user = user
controller.save();
错误消息是:
groovy.lang.MissingMethodException:否 方法签名:静态 com.baufest.insside.user.User.get() 是 适用于参数类型: (java.lang.Integer) 值: 1< /p>
我的我猜测我应该模拟 user
对象,但不知道如何操作。
I'm trying to write a simple integration test, but having some trouble with Domain Objects. I've read on unit testing but can't figure it out.
This is my simple test:
User user = User.get(1)
controller.params.userid = "1"
controller.session.user = user
controller.save();
The error message is:
groovy.lang.MissingMethodException: No
signature of method: static
com.baufest.insside.user.User.get() is
applicable for argument types:
(java.lang.Integer) values: 1
My guess is that I should mock the user
object, but don't know how.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你说你正在集成测试,但看起来你正在单元测试。测试是在测试/集成还是测试/单元下?单元测试需要模拟,但集成测试有一个初始化的 Spring 应用程序上下文和 Hibernate,并针对内存数据库运行。
用户指南对此进行了描述,位于 http://grails.org/doc/latest/(您引用了较旧的 1.1 版本)。
要模拟 User 类,只需在 setUp 或测试方法中使用一个或多个测试实例调用mockDomain:
You say that you're integration testing, but it looks like you're unit testing. Is the test under test/integration or test/unit? Unit tests need mocking, but integration tests have an initialized Spring application context and Hibernate, and run against an in-memory database.
This is described in the user guide, which is at http://grails.org/doc/latest/ (you reference an older 1.1 version).
To mock the User class, just call mockDomain with one or more test instances either in setUp or in the test method: