Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
单元测试android.provider_Android_Unit Testing_Android Testing - Fatal编程技术网

单元测试android.provider

单元测试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

我试图提供100%的测试覆盖率,但我仍然坚持使用某些Android方法,这是一个很好的例子:

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这正是我在问题中所说的,我如何模拟未传入的提供程序?