简体   繁体   English

Android Studio Robolectric资源文件夹

[英]Android Studio Robolectric resource folder

I have a workspace in the android studio that consists of the app projects and dependency android library project. 我在android studio中有一个工作区,其中包含应用程序项目和依赖项android库项目。

I have a unit test in the app project that tests the class that loads the string from both app project resources and the dependency library project resources. 我在应用程序项目中有一个单元测试,该单元测试测试从应用程序项目资源和依赖库项目资源中加载字符串的类。

When I run the unit test in Roboletric I get resource not found exception when the tested class tries to load the string from the library project resources. 当我在Roboletric中运行单元测试时,当被测试的类尝试从库项目资源中加载字符串时,我找不到资源异常。

How to fix this issue? 如何解决这个问题? How do I specify both the app and the dependency library resource directories for Robolectric to use? 如何为Robolectric指定应用程序和依赖库资源目录?

It's possible to do this by customizing the resource paths loaded during the initialization of the RobolectricTestRunner . 为此,可以通过定制在RobolectricTestRunner初始化期间加载的资源路径来实现

There's a good example of how to do this posted in this solution: 有一个很好的示例说明了如何在此解决方案中发布此操作:

https://stackoverflow.com/a/29223625/3063884 https://stackoverflow.com/a/29223625/3063884

android {
  testOptions {
    unitTests {
      includeAndroidResources = true
    }
  }
}

in app/build.gradle seems to be a preferred option to load resources for me. 在app / build.gradle中似乎是为我加载资源的首选选项。

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

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