Friday 9 June 2017

EasyMock & PowerMock Tutorial

EasyMock is an open source testing framework to unit test Java applications. It is released under the Apache License. Where as PowerMock is an open source mocking library that extends mocking frameworks like EasyMock, Mockito. PowerMock provides two extension APIS.
         a. For EasyMock
         b. For Mockito

To use PowerMock,
         a. we require either EasyMock (or) Mockito
         b. Test frameworks like JUnit, TestNG
        
Currently PowerMock supports JUnit and TestNG. I am going to use PowerMock, EasyMock and Junit combination for this tutorial series. Most of the mocking frameworks in Java can't mock private, static and final methods. By using PowerMock, we can extend the frameworks like EasyMock and can able to mock private static methods.

I am going to use following maven dependencies.
 <dependencies>
  <!-- https://mvnrepository.com/artifact/org.easymock/easymock -->
  <dependency>
   <groupId>org.easymock</groupId>
   <artifactId>easymock</artifactId>
   <version>3.4</version>
  </dependency>

  <!-- https://mvnrepository.com/artifact/org.powermock/powermock-module-junit4 -->
  <dependency>
   <groupId>org.powermock</groupId>
   <artifactId>powermock-module-junit4</artifactId>
   <version>1.6.6</version>
  </dependency>

  <!-- https://mvnrepository.com/artifact/org.powermock/powermock-api-easymock -->
  <dependency>
   <groupId>org.powermock</groupId>
   <artifactId>powermock-api-easymock</artifactId>
   <version>1.6.6</version>
  </dependency>

 </dependencies>


Previous                                                 Next                                                 Home

No comments:

Post a Comment