I am completely baffled while trying to use EasyMock. Does anybody know of a (very) gentle introduction to EasyMock?
I already heavily use TDD, and I use mocking (which I guess is almost a prerequisite for doing TDD). I have just never used a framework for mocking before.
EasyMock is a mocking framework, JAVA-based library that is used for effective unit testing of JAVA applications. EasyMock is used to mock interfaces so that a dummy functionality can be added to a mock interface that can be used in unit testing.
The expect() method tells EasyMock to simulate a method with certain arguments. The andReturn() method defines the return value of this method for the specified method parameters. The times() method defines how often the Mock object will be called. The replay() method is called to make the Mock object available.
EasyMock also supports injecting mocks using annotations. To use them, we need to run our unit tests with EasyMockRunner so that it processes @Mock and @TestSubject annotations. Equivalent to mock(…), a mock will be injected into fields annotated with @Mock.
When we create a mock object using EasyMock. createMock(), the order of execution of the method does not matter. Create a java class file named TestRunner in C:\> EasyMock_WORKSPACE to execute Test case(s).
Here are some articles you might like:
You could also check out other mocking frameworks such as Mockito, PowerMock and JMockit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With