尽管在 .andReturn 中设置了新对象,EasyMock Expect 方法始终返回 null
我的源代码为:
response = getRequestService().retrieveResponse(baseRequest);
data = response.getStoredData(); ---> (1)
我的测试用例编写为:
RequestService requestService = EasyMock.createNiceMock(RequestService .class);
BaseRequest baseRequest = new BaseRequest();
BaseResponse response = new BaseResponse();
expect(requestService .retrieveResponse(EasyMock.eq(baseRequest))).andReturn(response)
replay(requestService );
但是,当我运行测试时,我总是在第 1 行收到 NullPointerException
。
有人可以帮我解决这个问题吗?
谢谢。
I have my source code as:
response = getRequestService().retrieveResponse(baseRequest);
data = response.getStoredData(); ---> (1)
And I have written my Test Case as :
RequestService requestService = EasyMock.createNiceMock(RequestService .class);
BaseRequest baseRequest = new BaseRequest();
BaseResponse response = new BaseResponse();
expect(requestService .retrieveResponse(EasyMock.eq(baseRequest))).andReturn(response)
replay(requestService );
However, when I run my test I am always getting a NullPointerException
at line 1.
Can somebody please help me on how to resolve this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我首先要检查的地方是确保 getRequestService() 调用返回对模拟请求服务的引用。您似乎尚未定义该行为,并且对
getRequestService()
的调用返回null
。The first place I would look would be to make sure the
getRequestService()
call returns a reference to your mock request service. It looks like you haven't yet defined that behavior, and the call togetRequestService()
is returningnull
.