Mockito API• Easy to use;• High learning Curve;• Excellent Documentation;• “stub-run-verify” concept;• Concept stub is separed of verification;• Clear code;
And the others?• Use “except-run-verify” concept; (it is not good)• Code is not as clear as Mockito;• Documentation is not as good as Mockito ‘s doc;• Verify and expect are bult-in in expect() method; (Mockito is separated. It is better)
Matcherswhen(myobjectMock.buy(any(BigDecimal.class)).thenReturn(true); NoteMockito offers some built-in such as: anyString, anyInt(), any(class). But we can create customized built-in. Our class must extends ArgumentMatcher.
void method• doAnswer, doNothing, doThrow or doReturndoThrow(new Exception()).when(mockObject).buy(new BigDecimal("-5000"))
Verify it possible check the number invocation of method• atLeastOnce(), atLeast(int), atMost(int), never()verify(mockobject,times(3)).buy(new BigDecimal("10000"))
More featuresCheck Mockito Documentation. There are many examples.http://docs.mockito.googlecode.com/hg/org/mockito/ Mockito.html
ConclusionIf you want to improve of quality in unit test use Mock.It will contribute to design, code, development etc.There are many APIs in market, but the most used are: EasyMock, Jmock and Mockito.