如何为android方法和类编写单元测试?
例如 :
public int dpToPx (Context context, int dp) {
float density = context.getResources().getDisplayMetrics().density;
return Math.round((float) dp * density);
}
如果您使用的是Android类,则无法编写单元测试。对于Android相关的东西,你需要写instrumented unit tests
参考:https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests