How to mock static variables using Mockito
What you will learn here about Mockito
- How to mock static variables using Mockito
While working with Junit sometimes we come to situation where we need to mock static variable. Here we will see how to mock static variables using Mockito.
How to mock static variables using Mockito
Please follow the following steps to know how to mock static variables using Mockito
1)First create simple maven project
2)Add power mock junit dependency in your pom.xml which is given below
3)Create a class whose test case you want write and which has private static data members which is shown below
4)Here we are using Whitebox.setInternalState method to set the value for protected static data members which is shown below