Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EasyMock gentle introduction?

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.

like image 376
Bjarke Freund-Hansen Avatar asked Aug 26 '11 12:08

Bjarke Freund-Hansen


People also ask

What is EasyMock used for?

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.

What is EasyMock expect?

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.

How do you mock on EasyMock?

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.

How do you make a simple 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).


1 Answers

Here are some articles you might like:

  • Easier testing with EasyMock
  • Unit testing with JUnit and EasyMock
  • Mock Object Testing With EasyMock 2
  • Getting Started with EasyMock2

You could also check out other mocking frameworks such as Mockito, PowerMock and JMockit.

like image 80
Jasper Avatar answered Sep 25 '22 18:09

Jasper