我想用easymock测试下面的代码。我创建了模拟套接字和模拟输入流,但我无法模拟读取方法。任何人都可以请帮我Easymock嘲笑inputstream读操作
byte[] lenbuf = new byte[2];
sock.getInputStream().read(lenbuf);
我想在我的单元测试以下
InputStream mockInputStream = createMock(InputStream.class);
expect(mockInputStream.read(new byte[2])).andReturn(2);
replay(mockInputStream);
它给了我下面的错误
Unexpected method call InputStream.read([0, 0]):
InputStream.read([0, 0]): expected: 1, actual: 0
感谢
使用匹配器。无论是EasyMock.aryEq()或EasyMock.capture(),取决于你想要测试它。 –