各种Mock工具比较

mockito

官方主页 http://code.google.com/p/mockito/

最新版本 1.9.5(2012-10-06)

Java mocking is dominated by expect-run-verify libraries like EasyMock or jMock. Mockito offers simpler and more intuitive approach: you ask questions about interactions after execution. Using mockito, you can verify what you want. Using expect-run-verify libraries you are often forced to look after irrelevant interactions.

 

No expect-run-verify also means that Mockito mocks are often ready without expensive setup upfront. They aim to be transparent and let the developer to focus on testing selected behavior rather than absorb attention.

 

Mockito has very slim API, almost no time is needed to start mocking. There is only one kind of mock, there is only one way of creating mocks. Just remember that stubbing goes before execution, verifications of interactions go afterwards. You'll soon notice how natural is that kind of mocking when TDD-ing java code.

 

Mockito has similar syntax to EasyMock, therefore you can refactor safely. Mockito doesn't understand the notion of 'expectation'. There is only stubbing and verifications.

 

Mockito VS EasyMock http://code.google.com/p/mockito/wiki/MockitoVSEasyMock

 

EasyMock

官方主页 http://easymock.org/

最新版本 3.2(2013-07-11)

EasyMock provides mock objects since 2001. With EasyMock, it's finally easy to mock. Due to EasyMock's unique style of recording expectations, most refactorings will not affect the Mock Objects. So EasyMock is a perfect fit for Test-Driven Development.

EasyMock 3.2  Add @Mock annotations and Android support.

 

PowerMock

官方主页 http://code.google.com/p/powermock/

最新版本 1.5.4(2014-01-29)

PowerMock is a framework that extend other mock libraries such as EasyMock with more powerful capabilities. PowerMock uses a custom classloader and bytecode manipulation to enable mocking of static methods, constructors, final classes and methods, private methods, removal of static initializers and more. By using a custom classloader no changes need to be done to the IDE or continuous integration servers which simplifies adoption. Developers familiar with the supported mock frameworks will find PowerMock easy to use, since the entire expectation API is the same, both for static methods and constructors. PowerMock aims to extend the existing API's with a small number of methods and annotations to enable the extra features. Currently PowerMock supports EasyMock and Mockito.

PowerMock简介 http://www.ibm.com/developerworks/cn/java/j-lo-powermock/

 

jMock

官方主页 http://jmock.org/

最新版本 2.6.0(2012-12-19)

 

jmockit

官方主页 http://code.google.com/p/jmockit/

最新版本 1.8(2013-04-21)

JMockit allows developers to write unit and integration tests without the testability issues typically found with other mocking APIs. Tests can easily be written that will mock final classes, static methods, constructors, and so on. There are no limitations.

 

Most importantly, with JMockit all programming practices, patterns, and styles are supported equally, without forcing developers to make compromises just for the sake of unit testing.

 

其他相关资料

Unitils 

官方主页 http://www.unitils.org

最新版本 3.3(2011-12-22)

    Unitils构建在DBUnit与EasyMock项目之上并与JUnit和TestNG相结合。支持数据库测试,支持利用mock对象进行测试并提供与Spring和Hibernate相集成。Unitils设计成以一种高度可配置和松散偶合的方式来添加这些服务到单元测试中。

你可能感兴趣的:(mockito,Powermock,jmock,easymock,jmockit)