Reputation: 711
I'm new to Robolectric and Mockito. I try to write a simple unit test, but the static final values from my Peferences class are null, and I can't find out how to solve it.
Upvotes: 0
Views: 215
Reputation: 638
Yes you can stub class level variables like below.
Example:
Class Abc{
private static final variableName = null;
-----;
----;
rest of the code;
}
--Steps to Mock private static fields using Powermockito.
1) Field field = PowerMockito.field(Abc.class,"variableName");
2) field.set(Abc.class, variableValue);
PS- Make sure that you have used @PrepareforTest(Abc.class);
Hope it's useful.
Upvotes: 1