EasyMockSupport - Easy Mock

What is a EasyMockSupport in EasyMock?

A utility or a helper class to test the classes is EasyMockSupport. The functions provided by it are as follows:

  • replayAll() – Registers all the created mocks in one batch.
  • verifyAll() – Verifies all the mock operations in one batch.
  • resetAll() – Resets all the mock operations in one batch.

Example

Step 1: Create an interface called CalculatorService to provide mathematical functions

File: CalculatorService.java

Step 2: Create a JAVA class to represent MathApplication

File: MathApplication.java

Step 3: Test the MathApplication class

The MathApplication class is tested by injecting in it a mock of calculatorService. Mock will be created by EasyMock.

File: MathApplicationTester.java

Step 4: Execute test cases

A java class file named TestRunner in C:\> EasyMock_WORKSPACEto execute Test case(s) is created

File: TestRunner.java

Step 5: Verify the Result

Compile the classes using javac compiler as follows:

The Test Runner is run to view the result:

The output is verified.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Easy Mock Topics