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:
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_
testOptions.unitTests.includeAndroidResources = true
option 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?
Remove android.enableUnitTestBinaryResources=true
from gradle.properties. It helps in my case.
Please refer all the comments on this issue here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.