I’m discovering ways how run tests for Android application with JUnit. So far I selected Robolectric because it gives faster and much easier feedback.
Unfortunately my first test stuck and I’m looking for a way to find out the cause. I tried to log @Before and @Test methods but looks like it stopped somewhere in runner initialization.
I’m using Robolectric 1.1, JUnit 4.8.2, IntelliJ IDEA and Android 4.1 SDK.
UPD: I moved further by pausing my test execution in IDEA and what I see that Runner is doing some job but looks like it stuck or have loop inside these methods:
getAndroidResourcePathByExecingWhichAndroid():327, ResourceLoader {com.xtremelabs.robolectric.res}
getAndroidResourceSubPath()
I haven’t found what’s causing this problem but was able to devise a workaround.
After looking at the robolectric source it seems that the ResourcePathLoader class tries many ways to get the resource path, the last of which is getAndroidResourcePathByExecingWhichAndroid().
Usually for Intellij it is supposed to lookup the SDK path from a “local.properties” file.
Intellij usually creates this file when you create a project from scratch but for some reason it was missing in my project.
So the workaround is to create the local.properties file and store it at the root level of your project, it should contain the lines
Where
<SDK_PATH>is the path where your android SDK exists. Now if your run your tests it should work.