简体   繁体   中英

how to write unit test for android method and class?

how to write unit test for android method and class?

for example :

public int dpToPx (Context context, int dp) {

float density = context.getResources().getDisplayMetrics().density;

return Math.round((float) dp * density);

}

https://developer.android.com/training/testing/unit-testing

You can not write Unit test if you are using Android classes. For Android related stuff you need to write instrumented unit tests

Reference: https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM