[英]Easy mock behaviour while requested
I was thinking, is it possible to mock whole object behavior with EasyMock, but in a way that once declared mock with all expected values and results is used several times without caring about the order of the requests ? 我当时在想,是否可以用EasyMock模拟整个对象的行为,但是一旦声明了带有所有期望值和结果的模拟,就可以使用多次而无需关心请求的顺序?
The purpose for this is to create an instance of mock for example in JUnit test @BeforeClass and use it in several @Test methods. 这样做的目的是在JUnit test @BeforeClass中创建一个模拟实例,并在多个@Test方法中使用它。
Thank you in advance for any input, 预先感谢您的任何投入,
Regards, P. 问候,体育。
如果您不希望验证对模拟的调用,并且唯一的目的是确保无论何时调用模拟上的特定方法,该方法都会始终返回相同的所需结果,您可以使用andStubReturn()
对其进行配置,例如
expect(mock.getMeaningOfLifeUniverseAndEverything()).andStubReturn(42);
I think you're really wanting two things: 我认为您确实想要两件事:
You do the latter like this: 您可以像这样进行后者:
expect(someMock.someMethod()).anyTimes().andReturn(someValue);
If your method will get different arguments each time it is called, you can use the anyObject() method to ignore the provided argument. 如果您的方法每次调用都会得到不同的参数,则可以使用anyObject()方法忽略提供的参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.