本文介绍了不可能的RuntimeException:存根与Robolectric的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've spent hours trying to figure this out.

我使用Maven构建和测试的IntelliJ IDEA与Robolectric的项目。我有Robolectric Android在POM前宣布,我已经使用了SDK部署,安装到我的本地回购。但我还是不断收到此错误:

I'm using Maven to build and test a project in IntelliJ IDEA with Robolectric. I have Robolectric declared before Android in the POM, and I've used the SDK deployer to install to my local repo. But I still keep getting this error:

了java.lang.RuntimeException:存根!      在android.net.Uri。$$ ROBO $$ Uri_30fc_parse(Uri.java:53)      在org.robolectric.byte code.ShadowWrangler $ InvocationPlan.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.runCh​​ild(BlockJUnit4ClassRunner.java:68)      在org.junit.runners.BlockJUnit4ClassRunner.runCh​​ild(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.runCh​​ildren(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是完全如下:

And my pom.xml is exactly as follows:

<?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的查询,我不知道。我认为是Uri.parse()有问题的电话是在我测试的Activity类;我试过评论调用出来,看看会发生什么,但异常仍然抛出。

AbstractModel is my own personal convenience library. It does not use the Uri class anywhere internally. As for Android-Query, I'm not sure. What I think is the problematic call to Uri.parse() is in the Activity class I'm testing; I've tried commenting the call out to see what would happen but the exception is still thrown.

我已经试过移动Robolectric依赖周围的的IntelliJ模块的配置,以确保他们实际上是被列入的Andr​​oid之前。我作为密切配合我的POM和.iml文件到RobolectricSample项目文件成为了可能。我还删除了所有的IntelliJ文件在项目树和重开的聚甲醛项目。什么也没有。

I've tried moving the Robolectric dependencies around in the IntelliJ module configuration to make sure they are in fact being included before Android. I've matched my POM and .iml files as closely to the RobolectricSample project files as possible. I've even deleted all the IntelliJ files in the project tree and re-opened the project from the POM. Nothing.

我绝对狼狈。我用尽了一切我能想到的。我正在考虑取消Robolectric为这个项目,只是运行的模拟器来测试应用程序。

I am absolutely flummoxed. I've tried everything I can think of. I'm considering scrapping Robolectric for this project and just running the app in the emulator to test.

推荐答案

我有同样的问题,因为你。之一,也是additional.

I'm have the same problem as you. And also one additional.

无用的文字切割

更新1。

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

Found this issue on github:https://github.com/pivotal/robolectric/issues/426

一些民族传言称,在Mac OS它的工作原理。

Some peoples talk that on mac os it works..

更新2。

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

Found workaround (comment by 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);
    }
}

指定 @RunWith(YourTestRunner.class)每个测试,采用Android的API。

Specify @RunWith(YourTestRunner.class) on each test which uses Android API.

更新3。

发出定额: https://github.com/pivotal/robolectric/pull/458

这篇关于不可能的RuntimeException:存根与Robolectric的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 06:21