当前位置: 首页 > 知识库问答 >
问题:

Robolectric中未建立的资源

师俊健
2023-03-14
WARNING: no system properties value for ro.build.date.utc
DEBUG: Loading resources for com.persistpalapp.android from ./../app/src/main/res...
java.lang.IllegalStateException: android.content.res.Resources$NotFoundException: String resource ID #0x7f0e0064
    at com.persistpalapp.android.RPApplication.init(RPApplication.java:107)
    at com.persistpalapp.android.RPApplication.onCreate(RPApplication.java:83)
    at com.persistpalapp.android.TestRPApplication.onCreate(TestRPApplication.java:35)
    at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:126)
    at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:440)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:222)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:77)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:56)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:158)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f0e0064
    at android.content.res.Resources.getText(Resources.java:239)
    at org.robolectric.shadows.ShadowResources.getText(ShadowResources.java:363)
    at android.content.res.Resources.getText(Resources.java)
    at android.content.res.Resources.getString(Resources.java:325)
    at com.persistpalapp.android.RPApplication.init(RPApplication.java:102)
    at com.persistpalapp.android.RPApplication.onCreate(RPApplication.java:83)
    at com.persistpalapp.android.TestRPApplication.onCreate(TestRPApplication.java:35)
    at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:126)
    at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:440)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:222)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:77)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:56)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:158)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
    ... 1 more

java.lang.RuntimeException: java.lang.IllegalStateException: android.content.res.Resources$NotFoundException: String resource ID #0x7f0e0064
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:226)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:77)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:56)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:158)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.IllegalStateException: android.content.res.Resources$NotFoundException: String resource ID #0x7f0e0064
    at com.persistpalapp.android.RPApplication.init(RPApplication.java:107)
    at com.persistpalapp.android.RPApplication.onCreate(RPApplication.java:83)
    at com.persistpalapp.android.TestRPApplication.onCreate(TestRPApplication.java:35)
    at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:126)
    at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:440)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:222)
    ... 19 more
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f0e0064
    at android.content.res.Resources.getText(Resources.java:239)
    at org.robolectric.shadows.ShadowResources.getText(ShadowResources.java:363)
    at android.content.res.Resources.getText(Resources.java)
    at android.content.res.Resources.getString(Resources.java:325)
    at com.persistpalapp.android.RPApplication.init(RPApplication.java:102)
    at com.persistpalapp.android.RPApplication.onCreate(RPApplication.java:83)
    at com.persistpalapp.android.TestRPApplication.onCreate(TestRPApplication.java:35)
    at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:126)
    at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:440)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:222)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:77)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:56)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:158)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
    ... 1 more


Process finished with exit code 255
@Config(manifest = C.MANIFEST, emulateSdk = 18, reportSdk = 18)
@RunWith(RobolectricTestRunner.class)
public class JSONDataHelperTest {...}

===================更多信息=======================

我正在使用

  • Android Studio 1.1 Beta 4
  • Roboletric 2.4
  • com.android.tools.build:gradle:1.0.1
  • com.github.jcandksolutions.gradle:android-unit-test:2.1.1
  • org.robolectric:robolectric-gradle-plugin:0.12.+
  1. 应用程序:主应用程序
  2. robolectric-tests:测试类

我的robolectric-tests build.Gradle:

evaluationDependsOn(':app')
apply plugin: 'java'

repositories {
    mavenCentral()

    def androidHome = System.getenv("ANDROID_HOME")
    // check that androidHome points to the android home dir
    println("android home dir: "+androidHome)

    maven {
        url "$androidHome/extras/android/m2repository/"
    }
}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    def androidModule = project(':app')
    compile androidModule

    println "androidModule classpath: "+androidModule.android.applicationVariants.toList().first().javaCompile.classpath
    testCompile androidModule.android.applicationVariants.toList().first().javaCompile.classpath
    testCompile androidModule.android.applicationVariants.toList().first().javaCompile.outputs.files
    testCompile files(androidModule.plugins.findPlugin("com.android.application").getBootClasspath())

    //testCompile 'junit:junit:4.12-beta-2'
    testCompile 'org.robolectric:robolectric:2.4'
    testCompile 'org.mockito:mockito-core:1.10.8'
    testCompile 'org.assertj:assertj-core:1.7.0'
    testCompile 'com.squareup:fest-android:1.0.8'
}



//prevent the "superClassName is empty" error for classes not annotated as tests
tasks.withType(Test) {
    scanForTestClasses = false
    include "**/*Test.class" // whatever Ant pattern matches your test class files
}

共有1个答案

濮阳景天
2023-03-14
    null
    null
 类似资料:
  • 我试图从匕首移植到剑柄,但我得到了这个构建错误 基本应用程序,预计使用@DefineComponent进行注释。已找到:@kotlin。Metadata(mv={1, 4, 1}, bv={1, 0, 3}, k=1, d1={“\u0000\u0012\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0

  • Robolectric 是一款Android单元测试框架,示例代码: @RunWith(RobolectricTestRunner.class)public class MyActivityTest { @Test public void clickingButton_shouldChangeResultsViewText() throws Exception { Activity ac

  • 使用跺脚时。js和sockjs,我可以很好地连接到Spring Boot后端。 在Angular5中使用stompjs和sockjs时,我不断遇到以下错误: InvalidStateError:连接尚未建立 有解决办法吗?只是添加了sockjs。正如本文中提到的,min.js并没有起到任何作用。 详细日志如下: 设置连接/1主管道。3388a5e3a20e64e3bdb8。捆js:1设置连接/2主

  • 根据这个链接,我可以创建一个测试应用程序,Robolectric将自动开始在测试中使用它。我不能让它运转起来。 我正在使用Dagger进行依赖注入,并为和创建了注入包装类。那么我的每个活动都扩展了包装器活动类,而不是简单的旧。

  • 我是robolectric新手,我只想运行简单测试。 我使用Android Studio=>Gradle 如何找到错误的真正源头?零点异常在哪里?