【问题标题】:how to write unit test for android method and class?如何为android方法和类编写单元测试?
【发布时间】:2018-08-29 10:08:51
【问题描述】:

如何为android方法和类编写单元测试?

例如:

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

【问题讨论】:

  • 使用 espresso 来正确的 android 仪器测试以获取上下文和 android 相关方法的访问权限

标签: android unit-testing


【解决方案1】:

如果您使用的是 Android 类,则不能编写单元测试。 Android相关的东西你需要写instrumented unit tests

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-02
    • 1970-01-01
    • 1970-01-01
    • 2019-06-12
    • 2020-06-30
    • 1970-01-01
    • 2019-12-22
    • 1970-01-01
    相关资源
    最近更新 更多