user3057944
user3057944

Reputation: 711

Robolectric and Mockinto

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

Answers (1)

Praveen Kumar Mekala
Praveen Kumar Mekala

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

Related Questions