[英]Can't run tests with Robolectric 4.0.1, 'packageDebugUnitTestForUnitTest' fails
My robolectric tests aren't working after upgrading to Robolectric 4.0.1. 升级到Robolectric 4.0.1后,我的robolectric测试无法正常工作。
In my gradle configuration I am using testOptions.unitTests.includeAndroidResources = true
and in gradle.properties android.enableUnitTestBinaryResources=true
. 在我的gradle配置中,我使用
testOptions.unitTests.includeAndroidResources = true
并在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.
FAILURE:构建因异常而失败。
- What went wrong: Execution failed for task ':packageDebugUnitTestForUnitTest'.
出了什么问题:任务执行失败':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_
索引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: testOptions.unitTests.includeAndroidResources = true
选项,那么我收到以下错误: android.content.res.Resources$NotFoundException: Resource ID #0x7f030007
android.content.res.Resources $ NotFoundException:资源ID#0x7f030007
In the line val someItems = ApplicationProvider.getApplicationContext()...
在行
val someItems = ApplicationProvider.getApplicationContext()...
Why did the tests work with version 3.6.1 but now they don't? 为什么测试适用于3.6.1版,但现在却没有?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.