Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以为循环中调用的模拟设置不同的期望?
考虑到用例,
while(condition){ List list = Database call //Call to be mocked .... Logic based on above response }
我们如何设置期望,例如第一次迭代返回对象列表,而第二次调用返回空列表?
尝试这个:
expect(mockDatabase.call()).andReturn(object1).once(); expect(mockDatabase.call()).andReturn(object2).once(); replay(mockDatabase);