How to test the order of mocked calls using EasyMock
It's easy enough in EasyMock to do:
EasyMock.expect(service.methodCall());
but I noticed that this does not test the order in which I execute the calls, which in a case that I am trying to test is very开发者_运维百科 important. Is there anyway to do this with EasyMock?
You can use the EasyMock.createStrictMock()
for creating a mock thats capable of checking the order of method calls.
http://easymock.org/EasyMock3_0_Documentation.html
(search for "Checking Method Call Order Between Mocks" in the above link for examples).
If you need to test the order across different mocked objects, you can use EasyMock.createStrictControl()
to create the mocks, run replay()
& verify()
.
This site has some handy sample code: http://www.michaelminella.com/testing/mock-controls-with-easymock.html (archive.org mirror)
精彩评论