Grails - 在单元测试中模拟 servletContext
我很难在单元测试中模拟 servletContext 。这就是我尝试执行此操作的方法:
import org.springframework.mock.web.MockServletContext
void testSomehing() {
def servletContext = new MockServletContext()
servletContext.numberOfCreditProvider = 2
[...]
}
我收到以下错误消息:
No such property: numberOfCreditProvider for class: org.springframework.mock.web.MockServletContext
非常感谢任何帮助。
I am having hard time mocking servletContext in a unit test. This is how I try to do it:
import org.springframework.mock.web.MockServletContext
void testSomehing() {
def servletContext = new MockServletContext()
servletContext.numberOfCreditProvider = 2
[...]
}
I get the following error message:
No such property: numberOfCreditProvider for class: org.springframework.mock.web.MockServletContext
Any help greatly apreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
Try
就其价值而言,似乎可以在单元测试和集成测试中设置属性,但属性只能在集成测试中设置。这种类似地图的功能似乎在单元测试中不起作用。
For what it's worth, it seems that it's possible to set
attributes
in both unit and integration tests, but properties can only be set in integration tests. That map-like ability does not seem to work in unit tests.