2012-09-27 4 views
3

AndroidAnnotations를 사용하여 애플리케이션을 개발했으며 유닛 테스트를 위해 Robolectric를 사용하고 싶습니다.Robolectric 및 AndroidAnnotations로 Android 테스팅

그래도 작동하지 않습니다. 응용 프로그램과 테스트는 단일 프로젝트에 배치됩니다. 소스는 /src/main/java이며, 테스트는 /src/test/java입니다. 두 폴더 모두 원본 폴더입니다. 이클립스의 JUnit 런처를 사용하여 이클립스에서 테스트를 실행하는 경우

내가 얻을 :

Class not found org.demoapp.MyActivityTest 
java.lang.ClassNotFoundException: org.demoapp.MyActivityTest 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693) 

커맨드 mvn clean test에서 실행 내가 얻을 : 모든 클래스 비록

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project demo-app: Compilation failure: 
[ERROR] \demo-app\src\test\java\org\demoapp\MyActivityTest.java:[3,16] package org.junit does not exist 
[ERROR] \demo-app\src\test\java\org\demoapp\MyActivityTest.java:[4,23] package org.junit.runner does not exist 
[ERROR] \demo-app\src\test\java\org\demoapp\MyActivityTest.java:[6,33] package com.xtremelabs.robolectric does not exist 
[ERROR] \demo-app\src\test\java\org\demoapp\MyActivityTest.java:[8,1] cannot find symbol 
[ERROR] symbol: class RunWith 
... 
... 

이클립스에서 컴파일합니다.

실제로 여기에 어떤 문제가 있는지 알 수 없습니다. 어디에서 시작해야합니까? 당신의 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/maven-v4_0_0.xsd"> 

    <modelVersion>4.0.0</modelVersion> 
    <groupId>org.demoapp</groupId> 
    <artifactId>demo-app</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>apk</packaging> 
    <name>Demo :: App</name> 

    <properties> 
     <environment>development</environment> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>com.google.android</groupId> 
      <artifactId>android</artifactId> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.commons</groupId> 
      <artifactId>commons-io</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>com.googlecode.libphonenumber</groupId> 
      <artifactId>libphonenumber</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>com.google.code.gson</groupId> 
      <artifactId>gson</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>commons-lang</groupId> 
      <artifactId>commons-lang</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>com.googlecode.androidannotations</groupId> 
      <artifactId>androidannotations</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>com.googlecode.androidannotations</groupId> 
      <artifactId>androidannotations</artifactId> 
      <classifier>api</classifier> 
     </dependency> 
     <dependency> 
      <groupId>com.pivotallabs</groupId> 
      <artifactId>robolectric</artifactId> 
      <version>1.1</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.8.2</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 

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

     <sourceDirectory>src</sourceDirectory> 

     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
        <encoding>UTF-8</encoding> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
       <artifactId>android-maven-plugin</artifactId> 
       <version>3.3.0</version> 
       <extensions>true</extensions> 
       <configuration> 
        <manifest> 
         <debuggable>true</debuggable> 
        </manifest> 
       </configuration> 
       <executions> 
        <execution> 
         <id>manifestUpdate</id> 
         <phase>process-resources</phase> 
         <goals> 
          <goal>manifest-update</goal> 
         </goals> 
        </execution> 
        <execution> 
         <id>alignApk</id> 
         <phase>package</phase> 
         <goals> 
          <goal>zipalign</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 

     <pluginManagement> 
      <plugins> 
       <plugin> 
        <artifactId>maven-compiler-plugin</artifactId> 
        <version>2.3.2</version> 
       </plugin> 
       <plugin> 
        <artifactId>maven-jarsigner-plugin</artifactId> 
        <version>1.2</version> 
       </plugin> 
       <plugin> 
        <artifactId>maven-resources-plugin</artifactId> 
        <version>2.5</version> 
        <configuration> 
         <encoding>UTF-8</encoding> 
        </configuration> 
       </plugin> 

       <plugin> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>build-helper-maven-plugin</artifactId> 
        <version>1.5</version> 
       </plugin> 
       <plugin> 
        <groupId>org.eclipse.m2e</groupId> 
        <artifactId>lifecycle-mapping</artifactId> 
        <version>1.0.0</version> 
        <configuration> 
         <lifecycleMappingMetadata> 
          <pluginExecutions> 
           <pluginExecution> 
            <pluginExecutionFilter> 
             <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
             <artifactId>android-maven-plugin</artifactId> 
             <versionRange>[3.2.0,)</versionRange> 
             <goals> 
              <goal>manifest-update</goal> 
             </goals> 
            </pluginExecutionFilter> 
            <action> 
             <execute /> 
            </action> 
           </pluginExecution> 
          </pluginExecutions> 
         </lifecycleMappingMetadata> 
        </configuration> 
       </plugin> 
      </plugins> 
     </pluginManagement> 
    </build> 

    <profiles> 
     <profile> 
      <id>development</id> 
      <activation> 
       <property> 
        <name>environment</name> 
        <value>!production</value> 
       </property> 
      </activation> 
      <properties> 
       <deployment.stage>In Development</deployment.stage> 
      </properties> 
     </profile> 
     <profile> 
      <id>production</id> 
      <properties> 
       <deployment.stage>In Production</deployment.stage> 
      </properties> 
     </profile> 
     <profile> 
      <id>release</id> 
      <activation> 
       <property> 
        <name>performRelease</name> 
        <value>true</value> 
       </property> 
      </activation> 
      <build> 
       <plugins> 
        <plugin> 
         <groupId>org.apache.maven.plugins</groupId> 
         <artifactId>maven-jarsigner-plugin</artifactId> 
         <executions> 
          <execution> 
           <id>signing</id> 
           <goals> 
            <goal>sign</goal> 
            <goal>verify</goal> 
           </goals> 
           <phase>package</phase> 
           <inherited>true</inherited> 
           <configuration> 
            <removeExistingSignatures>true</removeExistingSignatures> 
            <archiveDirectory /> 
            <includes> 
             <include>${project.build.directory}/${project.artifactId}.apk</include> 
            </includes> 
            <keystore>keystore/keys.keystore</keystore> 
            <alias>alias</alias> 
            <storepass>${sign.storepass}</storepass> 
            <keypass>${sign.keypass}</keypass> 
            <verbose>true</verbose> 
           </configuration> 
          </execution> 
         </executions> 
        </plugin> 
        <plugin> 
         <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
         <artifactId>android-maven-plugin</artifactId> 
         <version>3.3.0</version> 
         <inherited>true</inherited> 
         <configuration> 
          <sign> 
           <debug>false</debug> 
          </sign> 
          <zipalign> 
           <verbose>true</verbose> 
           <inputApk>${project.build.directory}/${project.artifactId}.apk</inputApk> 
           <outputApk>${project.build.directory}/${project.artifactId}-signed-aligned.apk 
           </outputApk> 
          </zipalign> 
          <manifest> 
           <debuggable>false</debuggable> 
           <versionName>${project.version}</versionName> 
           <versionCodeAutoIncrement>true</versionCodeAutoIncrement> 
          </manifest> 
          <proguard> 
           <skip>true</skip> 
          </proguard> 
         </configuration> 
         <executions> 
          <execution> 
           <id>manifestUpdate</id> 
           <phase>process-resources</phase> 
           <goals> 
            <goal>manifest-update</goal> 
           </goals> 
          </execution> 
          <execution> 
           <id>alignApk</id> 
           <phase>package</phase> 
           <goals> 
            <goal>zipalign</goal> 
           </goals> 
          </execution> 
         </executions> 
        </plugin> 
       </plugins> 
      </build> 
     </profile> 
    </profiles> 

    <dependencyManagement> 
     <dependencies> 
      <dependency> 
       <groupId>com.google.android</groupId> 
       <artifactId>android</artifactId> 
       <version>2.3.1</version> 
      </dependency> 
      <dependency> 
       <groupId>org.apache.commons</groupId> 
       <artifactId>commons-io</artifactId> 
       <version>1.3.2</version> 
      </dependency> 
      <dependency> 
       <groupId>com.googlecode.libphonenumber</groupId> 
       <artifactId>libphonenumber</artifactId> 
       <version>5.1</version> 
      </dependency> 
      <dependency> 
       <groupId>com.google.code.gson</groupId> 
       <artifactId>gson</artifactId> 
       <version>2.2.2</version> 
      </dependency> 
      <dependency> 
       <groupId>commons-lang</groupId> 
       <artifactId>commons-lang</artifactId> 
       <version>2.6</version> 
      </dependency> 
      <dependency> 
       <groupId>com.googlecode.androidannotations</groupId> 
       <artifactId>androidannotations</artifactId> 
       <version>2.6</version> 
       <scope>provided</scope> 
      </dependency> 
      <dependency> 
       <groupId>com.googlecode.androidannotations</groupId> 
       <artifactId>androidannotations</artifactId> 
       <classifier>api</classifier> 
       <version>2.6</version> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 
</project> 
+0

프로젝트의 pom.xml을 첨부하십시오. – yorkw

+0

추가 된 프로젝트의 pom.xml –

+0

첫 번째 오류는 알려진 버그 (아래 내 의견 참조)이지만 두 번째 오류 로그에 따라 명령 줄을 통해 실행할 수 있어야합니다. 프로젝트의 클래스 패스. – yorkw

답변

3

, 당신은 src에 소스 디렉토리를 설정,하지만 당신은 소스 src/test/java에서 src/main/java 폴더와 시험에 있다고 말한다.

<sourceDirectory>src</sourceDirectory>을 제거 할 수 있습니까? Maven이 기본 파일 구조를 사용하고 있습니까?

또한 지금까지 Eclipse에서 robolectric로 단위 테스트를 시작할 수 없었습니다 ...하지만 maven에서도 작동합니다.

+1

이것은 m2e-android (또는 아마도 m2e)의 [알려진 버그] (https://github.com/rgladwell/m2e-android/issues/52)입니다. 근본 원인은 Eclipse라고 생각합니다. JUnit Runner는 Android ADT가 기본으로 사용했던 디렉토리와 다른 출력 디렉토리를 선호합니다. [releated bug] (https://github.com/rgladwell/m2e-android/issues/15)의 의견을 참조하십시오. 나는 bin/target/classes에 수동으로 내용을 복사하여 Eclipse JUnit Test 노래를 만들 수있다. 알다시피, 매번 코드가 수정 될 때마다이 작업을 수행해야하므로 상당히 더럽다. – yorkw

+0

앞으로 나아가고 있습니다. :) 제 자리에는 다른 것을 넣어야합니까? 현재로서는 'java.lang.TypeNotPresentException : 유형 com.google.android.maps.GeoPoint not present'오류가 발생합니다. –

+1

다음 종속성을 추가 했습니까? \t \t \t 이 com.google.android.maps \t \t \t \t 10_r2 \t \t 내가 그것을 사용하지 않더라도 나는 그것을 필요 \t DayS

관련 문제