开发者

Are there any automocking libraries in the Java world?

开发者 https://www.devze.com 2022-12-15 09:17 出处:网络
I\'m looking for something similar to the structuremap or eleution automocking container开发者_C百科s in the .NET worldYes, for Java there is the Unitils Mock library, which provides @TestedObject and

I'm looking for something similar to the structuremap or eleution automocking container开发者_C百科s in the .NET world


Yes, for Java there is the Unitils Mock library, which provides @TestedObject and @InjectInto... annotations for automatic injection of declarative mocks into tested objects.

Another option is JMockit, but it currently does not automatically inject its mocks into tested objects. OTOH, it does create mock objects declaratively, assigning them to instance fields or passing them as test method arguments; so, there is no "createMock" method.

The use of DI is important for mocking APIs such as Unitils Mock, EasyMock, jMock, and Mockito, because they always require mock instances to be passed to code under test. With JMockit, though, DI can be used just the same, but is unnecessary since instances created internally by code under test will get mocked transparently.


For Guice there is http://jukito.org

0

精彩评论

暂无评论...
验证码 换一张
取 消