Runtime Exception运行robolectric测试IntelliJ

时间:2013-04-06 09:37:05

标签: android intellij-idea robolectric

在IntelliJ中运行我的robolectric测试时,我得到:

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 ...

ANDROID_HOME已设置,但InteliJ似乎找不到它。

2 个答案:

答案 0 :(得分:2)

通过在项目的根目录中运行以下内容,在sdk.dir文件中设置local.properties

$ android update project -p .

设置local.properties文件是一种适用于大多数IDE的解决方案,因为您无需担心传递环境变量。

我是从Unable to find Android SDK得到的。您可以尝试其他几种选择。

答案 1 :(得分:0)

  • 转到“运行配置”(运行 - > EditConfigurations ..)
  • 从左侧选择您的测试(在JUnit下)
  • 在配置选项卡中,转到环境变量部分并添加指向您的sdk的环境变量ANDROID_HOME
  • 再次应用,构建并运行测试

注意:您可以在JUnit默认设置中添加它,这样您就不必为每个测试类做到这一点