简体   繁体   中英

Runtime Exception running robolectric tests IntelliJ

When running my robolectric tests in IntelliJ I get:

Warning: an error occurred while binding shadow class: ShadowGeoPoint
Warning: an error occurred while binding shadow class: ShadowItemizedOverlay
Warning: an error occurred while binding shadow class: ShadowMapController
Warning: an error occurred while binding shadow class: ShadowMapActivity
Warning: an error occurred while binding shadow class: ShadowMapView
Warning: an error occurred while binding shadow class: ShadowOverlayItem
WARNING: Unable to find path to Android SDK

java.lang.RuntimeException: java.lang.NullPointerException
    at com.xtremelabs.robolectric.res.ResourceLoader.init(ResourceLoader.java:158)
    at com.xtremelabs.robolectric.res.ResourceLoader.setLayoutQualifierSearchPath(ResourceLoader.java:599)
    at com.xtremelabs.robolectric.RobolectricTestRunner.setupApplicationState(RobolectricTestRunner.java:367)
    at com.xtremelabs.robolectric.RobolectricTestRunner.internalBeforeTest(RobolectricTestRunner.java:311)
    at com.xtremelabs.robolectric.RobolectricTestRunner.methodBlock(RobolectricTestRunner.java:278)
    at ...

The ANDROID_HOME ist set but InteliJ does not seem to find it.

Set the sdk.dir in a local.properties file by running the following in your project's root dir:

$ android update project -p .

Setting up a local.properties file is a solution that will work for most IDEs since you don't need to worry about getting environment variables passed around.

I got this from Unable to find Android SDK . There are also few other options which you may try.

  • Go to Run Configurations (Run -> EditConfigurations..)
  • Select your test from the left hand side (under JUnit)
  • In the configurations tab, go to Environment Variables section and add an environment variable ANDROID_HOME pointing to your sdk
  • Apply, build and run the test again

Note : You can add this in the JUnit default settings, so that you don't have to do for each test class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM