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

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -