测试中的getContentResolver(Android)

时间:2018-08-16 06:58:51

标签: android-contentresolver

当我尝试启动contentProvider.query时,我总是收到null。我想获取一个资源文件,我真的想要访问任何文件,我正在测试将文件(除了图像)上传到服务器。在普通代码中(无需测试),我可以毫无问题地做到这一点

var routerApp = angular.module("routerApp", ["ui.router"], ['ui.materialize']);

routerApp.controller('mainCtrl', ["$scope", function ($scope) {
        $scope.select = {
            value: "Option1",
            choices: ["Option1", "I'm an option", "This is materialize", "No, this is Patrick."]
        };

routerApp.config(
   ["$stateProvider", "$urlRouterProvider",
      function ($stateProvider, $urlRouterProvider) {

         $urlRouterProvider.otherwise("/template1");

         $stateProvider
            .state("template1", {
               url: "/template1",
               templateUrl: "template1.html",
               controller: "tmp1Controller"
            })
            .state("template2", {
               url: "/template2",
               templateUrl: "template2.html",
               controller: "tmp2Controller"
            });
      }
   ]);

routerApp.controller("mainCtrl", ["$scope",
   function ($scope) {

   }
]);
routerApp.controller("tmp1Controller", ["$scope",
   function ($scope) {

   }
]);

routerApp.controller("tmp2Controller", ["$scope",
   function ($scope) {

   }
]);

但是,如果我可以恢复的话,它是一个图像:

var uri = Uri.parse("android.resource://" + context!!.getPackageName() + "/"
            + R.raw.my_file)
//var uri = Uri.parse("content://" + context!!.getPackageName() + "/"
            + R.raw.my_file)

context = InstrumentationRegistry.getTargetContext()
context2 = InstrumentationRegistry.getContext()
contentResolverMock = MockContentResolver()

contentResolverMock.query(uri, null, null, null, null)
context2.getContentResolver().query(uri, null, null, null, null)
context.getContentResolver().query(uri, null, null, null, null)

我在做什么错了?

0 个答案:

没有答案