Impossible RuntimeException:带有 Robolectric 的存根

2023-12-07

我花了几个小时试图弄清楚这一点。

我正在使用 Maven 通过 Robolectric 在 IntelliJ IDEA 中构建和测试项目。我在 POM 中的 Android 之前声明了 Robolectric,并且我已使用 SDK 部署程序安装到我的本地存储库。但我仍然不断收到此错误:

java.lang.RuntimeException:存根! 在 android.net.Uri.$$robo$$Uri_30fc_parse(Uri.java:53) 在 org.robolectric.bytecode.ShadowWrangler$InitationPlan.callOriginal(ShadowWrangler.java:591) 在 android.net.Uri.parse(Uri.java) 在 org.robolectric.shadows.ShadowMediaStore.reset(ShadowMediaStore.java:27) 在 org.robolectric.Robolectric.resetStaticState(Robolectric.java:821) 在 org.robolectric.RobolectricTestRunner.resetStaticState(RobolectricTestRunner.java:224) 在 org.robolectric.RobolectricTestRunner.internalBeforeTest(RobolectricTestRunner.java:133) 在 org.robolectric.RobolectricTestRunner.methodBlock(RobolectricTestRunner.java:96) 在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) 在 org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) 在 org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) 在 org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) 在 org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) 在 org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) 在 org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) 在 org.junit.runners.ParentRunner.run(ParentRunner.java:300) 在 org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264) 在 org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153) 在 org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124) 在 org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2(ReflectionUtils.java:208) 在 org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:158) 在 org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:86) 在 org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153) 在 org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:95)

我的pom.xml完全如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.jemson</groupId>
<artifactId>notecloud-mobile</artifactId>
<version>.01</version>
<packaging>apk</packaging>
<name>Note-Cloud Mobile</name>

<profiles>
    <profile>
        <id>offline</id>
        <properties>
            <config.scheme>http://</config.scheme>
            <config.host>10.0.2.2</config.host>
            <config.path>/notecloudtest/index.html</config.path>
        </properties>
    </profile>
    <profile>
        <id>online</id>
        <properties>
            <config.scheme></config.scheme>
            <config.host></config.host>
            <config.path></config.path>
        </properties>

    </profile>
</profiles>

<dependencies>
    <dependency>
        <groupId>com.logician</groupId>
        <artifactId>abstractmodel</artifactId>
        <version>1</version>
    </dependency>
    <dependency>
        <groupId>com.androidquery</groupId>
        <artifactId>android-query</artifactId>
        <version>0.24.3</version>
    </dependency>

    <dependency>
        <groupId>org.robolectric</groupId>
        <artifactId>robolectric</artifactId>
        <version>2.0-alpha-2</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-core</artifactId>
        <version>1.2</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>com.googlecode.androidannotations</groupId>
        <artifactId>androidannotations</artifactId>
        <version>2.7</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.googlecode.androidannotations</groupId>
        <artifactId>androidannotations-api</artifactId>
        <version>2.7</version>
    </dependency>


    <dependency>
        <groupId>android</groupId>
        <artifactId>android</artifactId>
        <version>4.2.2_r2</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>android.support</groupId>
        <artifactId>compatibility-v4</artifactId>
        <version>12</version>
    </dependency>

</dependencies>


<build>
    <finalName>${project.artifactId}</finalName>
        <plugins>

            <plugin>
                <groupId>com.google.code.maven-replacer-plugin</groupId>
                <artifactId>replacer</artifactId>
                <version>1.5.2</version>
                <executions>
                    <execution>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>replace</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <file>templates/Config.java</file>
                    <outputFile>src/main/java/org/jemson/notecloud/Config.java</outputFile>
                    <replacements>
                        <replacement>
                            <token>#scheme</token>
                            <value>${config.scheme}</value>
                        </replacement>
                        <replacement>
                            <token>#host</token>
                            <value>${config.host}</value>
                        </replacement>
                        <replacement>
                            <token>#path</token>
                            <value>${config.path}</value>
                        </replacement>
                    </replacements>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>

            <plugin>
                <!-- See http://code.google.com/p/maven-android-plugin/ -->
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>3.4.1</version>
                <configuration>
                    <sdk>
                        <platform>17</platform>
                    </sdk>
                </configuration>
                <extensions>true</extensions>
            </plugin>


        </plugins>
</build>

AbstractModel 是我自己的个人便利库。它在内部的任何地方都不使用 Uri 类。至于Android-Query,我不确定。我认为对 Uri.parse() 的有问题的调用位于我正在测试的 Activity 类中;我尝试对调用进行评论以查看会发生什么,但仍然引发异常。

我尝试在 IntelliJ 模块配置中移动 Robolectric 依赖项,以确保它们实际上包含在 Android 之前。我已将 POM 和 .iml 文件与 RobolectricSample 项目文件尽可能匹配。我什至删除了项目树中的所有 IntelliJ 文件,并从 POM 重新打开了该项目。没有什么。

我完全困惑了。我已经尝试了我能想到的一切。我正在考虑放弃该项目的 Robolectric,而只是在模拟器中运行该应用程序进行测试。


我和你有同样的问题。还有一个额外的.

无用的文本剪切

更新1。

在github上发现这个问题:https://github.com/pivotal/robolectric/issues/426

有些人说在 macOS 上它可以工作..

更新2。

找到解决方法(评论者esam091):

public class YourTestRunner extends RobolectricTestRunner
{
    public YourTestRunner(Class<?> testClass) throws InitializationError
    {
        super(RobolectricContext.bootstrap(YourTestRunner.class, testClass,
            new RobolectricContext.Factory()
            {
                @Override
                public RobolectricContext create()
                {
                    return new RobolectricContext()
                    {
                        @Override
                        public boolean useAsm() // this override does the trick
                        {
                            return false;
                        }

                        @Override
                        protected AndroidManifest createAppManifest()
                        {
                            return new AndroidManifest(
                                new File("YourApp/src/main/android/AndroidManifest.xml"),
                                new File("YourApp/src/main/android/resources"));
                        }
                    };
                }
            }));
    }

    @Override
    public void prepareTest(Object test)
    {
        RoboGuice.injectMembers(Robolectric.application, test);
    }
}

Specify @RunWith(YourTestRunner.class)在每个使用 Android API 的测试中。

更新3。

已修复问题:https://github.com/pivotal/robolectric/pull/458

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Impossible RuntimeException:带有 Robolectric 的存根 的相关文章

随机推荐

  • 使用QT Creator如何将执行级别设置为requireAdministrator

    基本上我需要能够编辑需要管理员权限才能编辑的文件 我知道在 Visual Studio 中为此使用了清单文件 但我知道 QT 没有这些 您可以将清单与 Qt 应用程序一起使用 但您必须半手动执行此操作 这篇博文使用 QtCreator 嵌入
  • 如何使用活动识别豁免从后台启动foregroundService?

    Android 12 添加了从后台启动 ForegroundService 的限制 并且该文档还提到了一些豁免 其中之一是 您的应用收到与地理围栏或活动识别转换相关的事件 我找不到任何文档来详细讨论它 这是我的问题 我是否必须在收到此事件后
  • 如何在 Django 中为用户模型创建密码字段?

    我对 Django 完全陌生 在我的 models py 中 我想要一个用户模型来表示登录应用程序的用户 我知道如何拥有 fname lname 电子邮件和用户名等字段 例如 只需添加 first name models CharField
  • 更新 Google Slides API 中的链接表

    我看到有一种方法可以更新幻灯片中的链接图表 RefreshSheetsChartRequest 但在我的演示文稿中 我从 Google 表格粘贴了表格 这些表格链接到电子表格中的数据 我可以通过单击幻灯片 UI 中的更新按钮来手动更新这些内
  • Android Studio:意外的顶级异常:

    我该如何解决这个错误 错误 任务 app dexDebug 执行失败 com android ide common process ProcessException org gradle process internal ExecExcep
  • 将 WPF 组合框绑定到用户设置属性

    我在 WPF 中有一个组合框 其中有 4 个静态值
  • Xgboost (GPU) 在预测时崩溃

    我在 Python 中使用 XGBoost GPU 版本 每当我尝试运行 predict 时它都会崩溃 它适用于较小的数据集 但对于我当前的问题 它不起作用 train final shape test final shape 631761
  • 执行存储在变量中的数学运算

    我有3个这样的变量 第一个 2 第二 5 操作 如何以编程方式将这个数学问题的解决方案分配给 answer 变量 我尝试过 eval 但这不起作用 eval 对于这样的事情应该工作得很好 请记住 eval 返回 NULL 除非您告诉它返回某
  • Microsoft Visual C++ 2008 Redistributable Package 可以自由重新分发吗

    我计划使用 py2exe 制作一个用 Python 2 6 开发的应用程序 看来我的应用程序需要 VC 可再发行组件 http www py2exe org index cgi Tutorial Step5 我已阅读本教程和可再发行许可协议
  • 将一个文件共享/挂载到 Pod 中的最佳方式是什么?

    我正在考虑使用秘密来挂载单个文件 但似乎您只能挂载会覆盖所有其他内容的目录 如何在不安装目录的情况下共享单个配置文件 例如 您有一个包含 2 个配置文件的 configmap kubectl create configmap config
  • 如何在 JavaScript 中的 Y 和 Z 范围内随机生成 X 个数字?

    例如我想生成5个unique1 到 10 之间的数字 结果应该是 1 到 10 之间的 5 个数字 例如 2 3 4 8 10 用您的值范围填充数组 打乱数组 选择前 5 个元素 如果范围非常大 并且您想要的值的数量非常小 例如 范围 1
  • CDI 在同一实例中调用拦截器注释方法

    这是我的 DAO 实现 我将加载整个表并在内存中缓存一段时间 ApplicationScoped public class DataAccessFacade Inject private EntityManager em CacheOutp
  • 如何向 spritekit 中的节点添加滑动手势

    我正在尝试向节点添加滑动手势 以便当用户滑动它时 它会离开屏幕 但我不断收到SIGABRT错误 Terminating app due to uncaught exception NSInvalidArgumentException rea
  • 如果我不随包分发 pytest 测试,如何组织它们?

    As pytest 文档中建议 我设置我的包的目的不是not将我的测试与我的包一起分发 setup py mypkg init py mypkg appmodule py tests test app py 但我对如何确保这些测试在存在时正
  • Flask:无法导入名称“app”

    尝试运行我的 python 文件updater py通过 SSH 连接到服务器并每隔几个设定的时间间隔运行一些命令 我正在使用 APScheduler 来运行该函数update printer from init py 最初我得到了一个wo
  • onKeyPress 对比onKeyUp 和 onKeyDown

    这三个事件有什么区别 经过谷歌搜索我发现 The onKeyDown当用户按下某个键时触发事件 The onKeyUp当用户释放按键时触发事件 The onKeyPress当用户按下并释放按键时触发事件 onKeyDown其次是onKeyU
  • 通过属性文件指定pom属性?

    由于我的构建系统的设计方式 RTC 构建引擎 我想通过属性文件向 Maven 提供属性值 而不是为每个属性指定 Dkey value 我在 S O 上发现了几个问题 如何从 Maven POM 中的文件设置构建属性 and 如何在 Mave
  • Java 11 上的泽西岛 1.19.4

    Jersey 1 19 4 可以在 Java 11 上运行吗 如果没有 是否有相当于 Jersey 1 19 4 的版本 支持相同的 api 并且仍然可以在 Java 11 上运行 您应该升级到2 29版 至少 从 Jersey 2 29
  • 使用 iBeacon 打开应用程序

    我对 iOs 7 1 的新版本感到非常兴奋 其中对 iBeacon 进行了重大更改 如下所述 http beekn net 2014 03 apple ios 7 1 launches major ibeacon improvement 和
  • Impossible RuntimeException:带有 Robolectric 的存根

    我花了几个小时试图弄清楚这一点 我正在使用 Maven 通过 Robolectric 在 IntelliJ IDEA 中构建和测试项目 我在 POM 中的 Android 之前声明了 Robolectric 并且我已使用 SDK 部署程序安