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

运行robolectric时出现未知错误

穆华彩
2023-03-14

我是robolectric新手,我只想运行简单测试。

我使用Android Studio=>Gradle

@RunWith(RobolectricTestRunner.class)
public class ExampleTest extends InstrumentationTestCase {

@Test
public void test() throws Exception {
    final int expected = 5;
    final int reality = 5;
    assertEquals(expected, reality);
}
}
 ./gradlew clean test --stacktrace

    test.ExampleTest > test FAILED
        java.lang.RuntimeException
            Caused by: java.lang.NullPointerException

    1 test completed, 1 failed
    :app:testDebug FAILED

    FAILURE: Build failed with an exception.

    * What went wrong:
    Execution failed for task ':app:testDebug'.
    > There were failing tests. See the report at: file:///Users/gburanov/code/mobile/Medoo.Android/app/build/test-report/debug/index.html

    * Try:
    Run with --info or --debug option to get more log output.

    * Exception is:

    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:testDebug'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:289)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:86)
        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
        at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)

如何找到错误的真正源头?零点异常在哪里?

共有1个答案

麹高远
2023-03-14

对于Robolectric,您不应该扩展InstrumentationTestCase。

 类似资料:
  • 我有一个 PS 脚本,用于在 Office 365 中创建新用户。我正在使用微软在线和 AzureAD 模块来执行我需要的一切。 我需要从我的Python脚本运行PS脚本,但它不工作,我得到了“未识别的cmdlet”错误。 PS脚本非常基本,它在连接到Msol服务时失败,并继续运行,就像一切正常一样。 我尝试为MSOnline和AzureAD添加导入模块,但没有成功。值得一提的是,该脚本本身确实有

  • 我正在尝试根据以下文档创建复合聚合:https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-bucket-composite-aggregation.html 我基本上遵循这个例子: 但每次尝试运行代码时,无论我尝试在哪个字段上聚合,都会出现以下错误: 我做了一些深入的研究,没有看到其他地方出现

  • 我正在使用ec2和ubuntu 18机器,并希望安装jupyter笔记本,我遵循了这个教程,并不断得到这个错误: Traceback(最近的调用为last):文件“/home/ubuntu/.local/bin/jupyter-notebook”,第11行,在sys.exit(main())文件“/home/ubuntu/.local/lib/python3.6/site-packages/jup

  • 我在上面有一个问题:我使用了提供的答案,但仍然击中了一个对象错误。你能看到我错过了什么吗?我在“cash_sheet.range(”C8“).pastespecial xlpastevalues”处找到了错误

  • 在我的环境中设置了JAVA_HOME之后,我在运行pig时得到了以下结果: 当我这么做的时候: 但是在我的环境中,JAVA_HOME是这样设置的: 运行于:Ubuntu 10.04.4 LTS java:java版本“1.6.0_21”Hadoop版本:Hadoop-0.20.203 PIG版本:PIG-0.11.1 env:term=Xterm shell=/bin/bash xdg_sessi

  • 代码: pom.xml依赖项: 我不明白发生了什么事,有人能帮忙吗?