Thursday, August 2, 2018

PowerMockito



If already mockito  is there why we should go for powermockito ?

Sol :  Mockito can't mock for the  below scenarios.

 1.  Final class
 2.  Static methods.
3.  New operator
4.  Constructor
5.  Private methods


If the external class will have any one of the case then mockito can't mock the object.


For likely  reasons  PowerMockito :  Mockito + Extra features

-->   It is an unit test  framework.

"The main objective of the powerMockito is without depending on exgternal systems/backends  developer test the code "

Extra features are  :

 1.  Final class
 2.  Static methods.
3.  New operator
4.  Constructor
5.  Private methods


How to mock an Object ?

Case 1 :  final classes or normal class

B mockb  =  PowerMocktio.mock(B.class)

Case 2 : static methods

PowerMocktio.mockStatic(B.class)

Case 3 : new operator

B mockb = PowerMocktio.mock(B.class);

PowerMockito.whenNew(B.class).withNoArgument().thenReturn(mockb);

//todo :  constructors,private methods

Expectations :
============

PowerMockito.when(mockb.m2(Matchers.any(--))).thenReturn

verify :Verify results.

No comments:

Post a Comment

Hyderabad Trip - Best Places to visit

 Best Places to Visit  in Hyderabad 1.        1. Golconda Fort Maps Link :   https://www.google.com/maps/dir/Aparna+Serene+Park,+Masj...