2013-03-24 3 views
2

나는 이것을 알아 내려고 노력했다.불가능한 RuntimeException : Robolectric과 스텁

Robolectric을 사용하여 IntelliJ IDEA에서 프로젝트를 빌드하고 테스트하는 데 Maven을 사용하고 있습니다. Robolectric을 POM의 Android 전에 선언하고 SDK 배포자를 사용하여 로컬 저장소에 설치했습니다.

java.lang.RuntimeException: Stub! at android.net.Uri.$$robo$$Uri_30fc_parse(Uri.java:53) at org.robolectric.bytecode.ShadowWrangler$InvocationPlan.callOriginal(ShadowWrangler.java:591) at android.net.Uri.parse(Uri.java) at org.robolectric.shadows.ShadowMediaStore.reset(ShadowMediaStore.java:27) at org.robolectric.Robolectric.resetStaticState(Robolectric.java:821) at org.robolectric.RobolectricTestRunner.resetStaticState(RobolectricTestRunner.java:224) at org.robolectric.RobolectricTestRunner.internalBeforeTest(RobolectricTestRunner.java:133) at org.robolectric.RobolectricTestRunner.methodBlock(RobolectricTestRunner.java:96) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2(ReflectionUtils.java:208) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:158) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:86) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153) at 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 클래스에있다. 무슨 일이 일어날 지 알아보기 위해 콜을 주석으로 써 넣으려고했지만 예외는 여전히 발생합니다.

Robolectric 의존성을 IntelliJ 모듈 구성에서 이동 시켜서 실제로 Android 이전에 포함되었는지 확인하려고했습니다. 내 POM 및 .iml 파일을 가능한 한 RobolectricSample 프로젝트 파일과 가깝게 일치 시켰습니다. 필자는 프로젝트 트리에서 IntelliJ 파일을 모두 삭제하고 POM에서 프로젝트를 다시 열었습니다. 아무것도.

나는 정말 놀랐다. 나는 내가 생각할 수있는 모든 것을 시도했다. 이 프로젝트에 Robolectric을 폐기하고 테스트를 위해 에뮬레이터에서 앱을 실행하는 것을 고려하고 있습니다.

답변

3

나는 당신과 같은 문제가 있습니다. 또한 additional도 있습니다.

useless text cut

업데이트 1

찾을 수 GitHub의에서이 문제 : https://github.com/pivotal/robolectric/issues/426

일부 사람들은 맥 OS에서 작동하는지 이야기 ..

업데이트 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); 
    } 
} 

안드로이드 API를 사용하는 각 시험에 @RunWith(YourTestRunner.class)를 지정합니다. 고정

업데이트 3.

문제 : 나는이 질문을 게시 한 후 https://github.com/pivotal/robolectric/pull/458

+0

그래, 난이 얼마 파악했다. 구현을 생각하고 있었지만 구현 시간은 에뮬레이터를 사용하여 수동으로 테스트하는 대신 단위 테스트를 사용하여 절약 한 시간과 균형을 이루지 않을 것이라고 결정했습니다. 어쩌면 내가이 프로젝트를 마친 후에. –