3

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:

  1. 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_

  1. If I remove the 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?

1

1 Answer 1

-1

Remove android.enableUnitTestBinaryResources=true from gradle.properties. It helps in my case.

Please refer all the comments on this issue here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.