android - Stub value of Build.VERSION.SDK_INT in Local Unit Test -


i wondering if there anyway stub value of build.version.sdk_int? suppose have following lines in classundertest:

if (build.version.sdk_int >= build.version_codes.jelly_bean) {     //do work }else{     //do work } 

how can cover code ?

i mean want run 2 tests different sdk_int enter both blocks.

is possible in android local unit tests using mockito/powermockito?

thanks

change value using reflection.

 static void setfinalstatic(field field, object newvalue) throws exception {     field.setaccessible(true);      field modifiersfield = field.class.getdeclaredfield("modifiers");     modifiersfield.setaccessible(true);     modifiersfield.setint(field, field.getmodifiers() & ~modifier.final);      field.set(null, newvalue);  } 

and then

 setfinalstatic(build.version.class.getfield("sdk_int"), 123); 

it tested. works.


Comments

Popular posts from this blog

AbotX : How do you create a parallel crawler that stays on and can be added to at run time from new requests -

testing - Detect whether test has failed within fixture -

android - Create single AAR file from multiple modules using Gradle -