单元测试android.provider
我试图提供100%的测试覆盖率,但我仍然坚持使用某些Android方法,这是一个很好的例子:单元测试android.provider,android,unit-testing,android-testing,Android,Unit Testing,Android Testing,我试图提供100%的测试覆盖率,但我仍然坚持使用某些Android方法,这是一个很好的例子: public static boolean areMockLocationsEnabled(Context context) { return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION).equals("1"); } 我无法模拟设置,因为它使用的是and
public static boolean areMockLocationsEnabled(Context context) {
return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION).equals("1");
}
我无法模拟设置,因为它使用的是android.provider,未传入。我已经阅读了ProviderTestCase2,但是我找不到很多例子。有没有办法模拟或注入这些android系统设置?这是我的问题,我如何对这个方法进行单元测试?你的代码在哪里?您尝试过什么?没有代码,我不知道如何模拟设置,因为它没有传入,并且是一个本地Android提供商。这是我的问题,我如何模拟它?您可以使用类似于
mockito
的框架模拟它,并使用roblectric
运行其他测试。Jarred这正是我在问题中所说的,我如何模拟未传入的提供程序?