简体   繁体   English

运行时异常运行robolectric测试IntelliJ

[英]Runtime Exception running robolectric tests IntelliJ

When running my robolectric tests in IntelliJ I get: 在IntelliJ中运行我的机器人测试时,我得到:

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. ANDROID_HOME ist集,但是InteliJ似乎找不到它。

Set the sdk.dir in a local.properties file by running the following in your project's root dir: 通过在项目的根目录中运行以下sdk.dir ,在local.properties文件中设置sdk.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. 设置local.properties文件是一种适用于大多数IDE的解决方案,因为您不必担心会传递环境变量。

I got this from Unable to find Android SDK . 我从Unable to find Android SDK获得此信息。 There are also few other options which you may try. 您也可以尝试其他几种选择。

  • Go to Run Configurations (Run -> EditConfigurations..) 转到运行配置(运行-> EditConfigurations ..)
  • Select your test from the left hand side (under JUnit) 从左侧选择测试(在JUnit下)
  • In the configurations tab, go to Environment Variables section and add an environment variable ANDROID_HOME pointing to your sdk 在“配置”标签中,转到“环境变量”部分,然后添加一个指向您的SDK的环境变量ANDROID_HOME
  • 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 注意:您可以在JUnit默认设置中添加它,这样就不必为每个测试类都做

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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