1

I have a workspace in the android studio that consists of the app projects and dependency android library project.

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.

How to fix this issue? How do I specify both the app and the dependency library resource directories for Robolectric to use?

Ram Koti
  • 2,203
  • 7
  • 26
  • 36
user1744147
  • 1,099
  • 13
  • 30
  • fix 1 - copy the resources to the app folder in a file called `duplications-for-tests.xml`. Fix 2 - override and provide your own test runner, then you can specify an "manifest" and tell robolectric where to look for resources – Blundell Oct 03 '14 at 14:55
  • Can you please elaborate both options? I cannot copy resources, there are a lot of them and they and in two different projects. This simply does not scale. Regarding custom test runner what from I checked it takes only one resource location and my resources are in two projects. – user1744147 Oct 06 '14 at 11:54
  • I'm looking for a solution to this too. – Andrea Baccega Oct 07 '14 at 21:45

2 Answers2

1

It's possible to do this by customizing the resource paths loaded during the initialization of the RobolectricTestRunner.

There's a good example of how to do this posted in this solution:

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

Community
  • 1
  • 1
CJBS
  • 15,147
  • 6
  • 86
  • 135
0
android {
  testOptions {
    unitTests {
      includeAndroidResources = true
    }
  }
}

in app/build.gradle seems to be a preferred option to load resources for me.

jknair0
  • 1,194
  • 13
  • 24