My robolectric tests aren't working after upgrading to Robolectric 4.0.1.
In my gradle configuration I am using testOptions.unitTests.includeAndroidResources = true and in gradle.properties android.enableUnitTestBinaryResources=true.
Here's a dummy test to use as en example:
@RunWith(RobolectricTestRunner::class)
internal class MyRobolectricTests
{
@Test
fun my_test()
{
val someItems = ApplicationProvider.getApplicationContext().resources.getStringArray(R.array.array_of_strings)
assertEquals(10, someItems.size)
}
}
I am experiencing 2 separate problems:
- If I run the test then I am getting the following message:
FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ':packageDebugUnitTestForUnitTest'.
Illegal character in opaque part at index 11: jar:file:C:\myproject\build\intermediates\apk_for_local_test\debugUnitTest\packageDebugUnitTestForUnitTest\apk-for-local-test.ap_
- If I remove the
testOptions.unitTests.includeAndroidResources = trueoption from the gradle config file then I am getting the following error:
android.content.res.Resources$NotFoundException: Resource ID #0x7f030007
In the line val someItems = ApplicationProvider.getApplicationContext()...
Why did the tests work with version 3.6.1 but now they don't?