Turn from:
http://billben.iteye.com/blog/1872196
http://harrywu304.blog.163.com/blog/static/8456603201141611147777/
Available Mock toolkit There are many, more common there are easymock, Jmock and Jmockit, and so on, in the end to choose which, jmockit the official network has a feature comparison list, very detailed:
Feature |
EasyMock |
Jmock |
Mockito |
Unitils Mock |
Powermock: EasyMock Api |
Powermock: Mockito Api |
Jmock It |
Invocation count constraints |
√ |
√ |
√ |
|
√ |
√ |
√ |
Recording strict expectations |
√ |
√ |
|
|
√ |
|
√ |
Explicit Verification |
|
|
√ |
√ |
|
√ |
√ |
Partial mocking |
√ |
|
√ |
√ |
√ |
√ |
√ |
No method call to switch from record to replay |
|
|
√ |
√ |
|
√ |
√ |
No Extra code for implicit verification |
|
|
N/A |
N/A |
|
N/A |
√ |
No Extra "Prepare for test" code |
√ |
√ |
√ |
√ |
|
|
√ |
No need to use @RunWith annotation or base Test class |
√ |
√ |
√ |
|
|
|
√ |
Consistent syntax between void and Non-void methods |
|
√ |
|
√ |
|
|
√ |
Argument matchers for some parameters only, Not all |
|
|
|
√ |
|
|
√ |
Easier argument matching based on properties of Value objects |
√ |
|
√ |
√ |
√ |
√ |
√ |
Cascading mocks |
|
|
√ |
√ |
|
√ |
√ |
Support for mocking multiple interfaces |
|
|
√ |
|
|
√ |
√ |
Support for mocking annotation types |
|
√ |
√ |
√ |
|
√ |
√ |
Partially ordered expectations |
|
√ |
|
|
|
|
√ |
Mocking of constructors and Final/static/native/private methods |
|
|
|
|
√ |
√ |
√ |
Declarative application of Mocks/stubs to Whole test Classes |
|
|
|
|
√ |
√ |
√ |
Auto-injection of mocks |
|
|
√ |
√ |
|
√ |
√ |
Mocking of "new-ed" objects |
|
|
|
|
√ |
√ |
√ |
Support for mocking enum types |
|
|
|
|
√ |
√ |
√ |
Declarative mocks for the test class (mock Fields |
|
|
√ |
√ |
√ |
√ |
√ |
Declarative mocks for test methods (Parameters, local fields) |
|