jeudi 3 mai 2018

Mocking build.MODEL with mockito

I'm using mockito and JUnit4 to create the tests in my project. One of my methods is working with the android.os.Build.MODEL and the android.os.Build.VERSION.RELEASE. To test it, I'm trying to mock this two. I've read in this same page that, for the version, I can use:

Whitebox.setInternalState(Build.VERSION.class, "SDK_INT", 16);

But trying to do the same with the model is giving me an error (You are trying to set a private static final String. Cannot set such fields!):

Whitebox.setInternalState(Build.class, "MODEL", "Nexus 12");

Is there any correct way to do it?

Aucun commentaire:

Enregistrer un commentaire