Take the following function as an example:
public static float convertPixelsToDp(float px, Context context){
return px / ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
In the function above, px
is altered by context.getResources().getDisplayMetrics().densityDpi
and DisplayMetrics.DENSITY_DEFAULT
. If developers use the same emulator, then a test could be written that works across developer machines. That doesn't seem scalable or correct.
Is there a way to set a mock device or default values for display metrics in order to create tests that work across developer machines?
from Testing functions that have Android device specific side effects
No comments:
Post a Comment