Using the file resources in Android POJO unit test

Since version 1.1 of Android Gradle Plugin we can run unit test on a local JVM on our development machine. It’s still experimental feature but I’ve found it’s fully usable.

Finally Android developers have lighweight build-in tool for unit testing :)
The times when we need third party libraries to test unit classes quickly seems to be gone :)

I had to implement a parser which operates on JSON data returned from REST API.
The first thing I thought was to get some sort of responses from the server and put them in local files.
This approach was the simplest way to make my parser work with proper data without any mocking stuff.
After a while I prepared simple test which was ready to read json from the file:

Unfortunately if you put response_with_missing_field.json directly in the sources directory or any other, getResources() returns null.
After quick research I realized the reason was the apk doesn’t contain any resource file at all.
So it’s going to be problem with build tool which ignores the resource.