mardi 29 mars 2016

How can I load a json file from an android unit test that is run with PowerMockRunner?

I am using PowerMockRunner to run my unit tests. I want to load some canned network response json files from my assets folder.

@RunWith(PowerMockRunner.class)

I am using this method to try to get the file.

private static File getFileFromPath(Object obj, String fileName) {
        ClassLoader classLoader = obj.getClass().getClassLoader();
        URL resource = classLoader.getResource(fileName);
        return new File(resource.getPath());
    }

However, when I evaluate this expression.

classLoader.getResource(".");

It shows that I am currently in this the directory below while running this test.

/Users/tylerpfaff/Library/Android/sdk/platforms/android-23/data/res/

Seeing as I'm in the platforms resource directory, there is no hope of me successfully loading my resources from my project's resource directory. What do I need to do to access my resource directory of my project?

Aucun commentaire:

Enregistrer un commentaire