tags:

views:

47

answers:

1

I'm looking for something similar to the structuremap or eleution automocking containers in the .NET world

A: 

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.

Rogerio