2013-01-09 100 views
0

我一直抨击我的头几天,所以我想它的时间问。Android测试使用Maven进行编译

我有一个android项目和一个android-test项目。我可以在eclipse中运行我的测试,并且这一切都很好。

所以现在我正在通过maven使用这些测试,以便我可以将它们用于CI。

无论如何长话短说我不能让maven编译/运行它们。我已经查看了android-maven-plugin提供的所有例子,但都无济于事。

主聚甲醛。

<groupId>com.xxx.x_android_finder</groupId> 
<artifactId>x_Android_Finder</artifactId> 
<version>1.0.2</version> 
<packaging>apk</packaging> 
<name>xxxx</name> 

<dependencies> 
    <!-- <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.8.1</version> 
      <scope>test</scope> 
    </dependency> --> 
    <dependency> 
     <groupId>com.google.android</groupId> 
     <artifactId>android</artifactId> 
     <version>4.0.1.2</version> 
     <scope>provided</scope> 
    </dependency> 

    <dependency> 
<groupId>com.google.android.maps</groupId> 
     <artifactId>maps</artifactId> 
     <version>15_r2</version> 
     <scope>provided</scope> 
    </dependency> 

    <dependency> 
     <groupId>com.actionbarsherlock</groupId> 
     <artifactId>library</artifactId> 
     <version>4.1.0</version> 
     <type>apklib</type> 
     <exclusions> 
      <exclusion> 
       <groupId>com.google.android</groupId> 
       <artifactId>support-v4</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 

    <dependency> 
     <groupId>com.actionbarsherlock</groupId> 
     <artifactId>plugin-maps</artifactId> 
     <version>4.1.0</version> 
    </dependency> 

    <dependency> 
     <groupId>net.hockeyapp.android</groupId> 
     <artifactId>HockeySDK</artifactId> 
     <version>2.0.2</version> 
     <type>apklib</type> 
    </dependency> 

    <dependency> 
     <groupId>com.codeslap</groupId> 
     <artifactId>android-facebook</artifactId> 
     <version>1.6</version> 
     <scope>compile</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.twitter4j</groupId> 
     <artifactId>twitter4j-core</artifactId> 
     <version>[3.0,)</version> 
    </dependency> 

</dependencies> 

<repositories> 
    <repository> 
     <id>jakewharton</id> 
     <url>http://r.jakewharton.com/maven/release/</url> 
    </repository> 
    <repository> 
     <id>codeslap</id> 
     <url>http://casidiablo.github.com/codeslap-maven/repository/</url> 
    </repository> 

</repositories> 

<build> 

    <plugins> 



     <plugin> 
      <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
      <artifactId>android-maven-plugin</artifactId> 
      <version>3.2.0</version> 
      <extensions>true</extensions> 

      <configuration> 
       <!-- replace resources with target specific --> 


       <renameManifestPackage>${customerPackage}</renameManifestPackage> 
       <resourceOverlayDirectory>${customerResources}</resourceOverlayDirectory> 

       <sign> 
        <debug>false</debug> 
       </sign> 
        <manifest> 
        <versionCodeAutoIncrement>true</versionCodeAutoIncrement> 
        </manifest> 
        <zipalign> 
        <inputApk>${project.build.directory}/${project.build.finalName}.apk</inputApk> 
        <outputApk>${project.build.directory}/x_Android_Finder.apk</outputApk> 
       </zipalign> 

       <proguard> 
        <skip>true</skip> 
       </proguard> 

       <sdk> 
        <!-- platform or api level (api level 4 = platform 1.6)--> 
        <platform>17</platform> 
       </sdk> 
       <assetsDirectory>${project.basedir}/${customerAssets}</assetsDirectory> 
       <resourceDirectory>${project.basedir}/res</resourceDirectory> 
      </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> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-jarsigner-plugin</artifactId> 
      <version>1.2</version> 
      <executions> 
       <execution> 
        <id>signing</id> 
        <goals> 
         <goal>sign</goal> 
        </goals> 
        <phase>package</phase> 

        <inherited>true</inherited> 
        <configuration> 
         <archiveDirectory></archiveDirectory> 
         <includes> 
          <include>target/*.apk</include> 
         </includes> 
         <keystore>../certificates/xxx.keystore</keystore> 
         <storepass>xxxx</storepass> 
         <keypass>xxxx</keypass> 
         <alias>csl</alias> 

        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

     <!-- <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-javadoc-plugin</artifactId> 
      <configuration> 
       <skip>true</skip> 
      </configuration> 
     </plugin> --> 

    </plugins> 
</build> 

测试POM

<artifactId>x_Android_Finder_Test</artifactId> 
    <packaging>apk</packaging> 
    <version>1.0.0</version> 
    <name>xxxxx</name> 


    <dependencies> 
     <dependency> 
      <groupId>com.google.android</groupId> 
      <artifactId>android-test</artifactId> 
      <version>1.5_r3</version> 
      </dependency> 

     <dependency> 
      <groupId>com.google.android</groupId> 
      <artifactId>android</artifactId> 
      <version>4.0.1.2</version> 
      <scope>provided</scope> 
     </dependency> 

     <dependency> 
      <groupId>com.google.android.maps</groupId> 
      <artifactId>maps</artifactId> 
      <version>15_r2</version> 
      <scope>provided</scope> 
     </dependency> 

     <dependency> 
      <groupId>com.actionbarsherlock</groupId> 
      <artifactId>library</artifactId> 
      <version>4.1.0</version> 
      <type>apklib</type> 
      <exclusions> 
       <exclusion> 
        <groupId>com.google.android</groupId> 
        <artifactId>support-v4</artifactId> 
       </exclusion> 
      </exclusions> 
     </dependency> 

     <dependency> 
      <groupId>com.actionbarsherlock</groupId> 
      <artifactId>plugin-maps</artifactId> 
      <version>4.1.0</version> 
     </dependency> 

     <dependency> 
      <groupId>com.connectionservices.csl_android_finder</groupId> 
      <artifactId>Csl_Android_Finder</artifactId> 
      <type>apk</type> 
      <version>1.0.2</version> 
     </dependency> 

     <dependency> 
      <groupId>com.connectionservices.csl_android_finder</groupId> 
      <artifactId>Csl_Android_Finder</artifactId> 
      <scope>provided</scope> 
      <type>jar</type> 
      <version>1.0.2</version> 
     </dependency> 


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

     <dependency> 
      <groupId>net.hockeyapp.android</groupId> 
      <artifactId>HockeySDK</artifactId> 
      <version>2.0.2</version> 
      <type>apklib</type> 
     </dependency> 

     <dependency> 
      <groupId>com.codeslap</groupId> 
      <artifactId>android-facebook</artifactId> 
      <version>1.6</version> 
      <scope>compile</scope> 
     </dependency> 

     <dependency> 
      <groupId>org.twitter4j</groupId> 
      <artifactId>twitter4j-core</artifactId> 
      <version>[3.0,)</version> 
     </dependency> 

     <dependency> 
      <groupId>com.jayway.android.robotium</groupId> 
      <artifactId>robotium-solo</artifactId> 
      <version>3.6</version> 
     </dependency> 

    </dependencies> 

    <repositories> 
     <repository> 
      <id>oss.sonatype.org-jayway-with-staging</id> 
      <url>http://oss.sonatype.org/content/groups/jayway-with-staging/</url> 
     </repository> 

     <repository> 
      <id>jakewharton</id> 
      <url>http://r.jakewharton.com/maven/release/</url> 
     </repository> 


     <repository> 
      <id>codeslap</id> 
      <url>http://casidiablo.github.com/codeslap-maven/repository/</url> 
     </repository> 

    </repositories> 

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


      <plugin> 
       <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
       <artifactId>android-maven-plugin</artifactId> 

       <configuration> 
        <sdk> 
         <platform>15</platform> 
        </sdk> 

      <test> 

         <createReport>true</createReport> 

        </test> 

       </configuration> 
       <extensions>true</extensions> 


      </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.13</version> 

       </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-jarsigner-plugin</artifactId> 
       <!-- <version>1.2</version> --> 
       <executions> 
        <execution> 
         <id>signing</id> 
         <goals> 
          <goal>sign</goal> 
         </goals> 
         <phase>package</phase> 

         <inherited>true</inherited> 
         <configuration> 
          <removeExistingSignatures>true</removeExistingSignatures> 

          <archiveDirectory></archiveDirectory> 
          <includes> 
           <include>target/*.apk</include> 
          </includes> 
          <keystore>../certificates/xxxx.keystore</keystore> 
          <storepass>xxx</storepass> 
          <keypass>xxxx</keypass> 
          <alias>csl</alias> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

项目正在主/ JAVA举行的测试/ ......在测试项目

我编译时使用MVN干净的测试

它呕吐的错误是

ERROR] /Users/aidenfry/AndroidHSF(trunknew)/x_Android_Finder_Parent/x_Android_Finder_Test/src/main/java/com/xxxxxxx/x_android_finder_test/FinderActivityTest.java:[27,7] cannot access junit.framework.TestCase 
[ERROR] class file for junit.framework.TestCase not found 
[ERROR] public class FinderActivityTest extends ActivityInstrumentationTestCase2<FinderActivity> { 
[ERROR] /Users/aidenfry/AndroidHSF(trunknew)/x_Android_Finder_Parent/x_Android_Finder_Test/src/main/java/com/xxxx/xx_android_finder_test/FinderActivityTest.java:[39,8] cannot find symbol 
[ERROR] symbol : variable super 
[ERROR] location: class 

我可以提供更多,但它们都与此类似,似乎找不到Junit lib?但我已经在依赖英国人那里。

如果有人可以帮助/提示我解决这个烂摊子,将非常感谢!

+0

根据您发布的代码,您已注释掉将解释消息的JUnit依赖项。 – khmarbaise

+0

顺便说一句:从不使用版本范围,如** [3.0,) ** – khmarbaise

+0

Ups。为什么你有两个pom文件?那是什么意思? – khmarbaise

回答

0

好吧,所以我就是这么做的。

我最初有我的测试用例在一个单独的模块/ eclipse项目。这似乎在扰乱我的东西。

将该类移入src/main/test下的主应用程序项目,现在修复了我所有的问题,谢谢!

1

万一有人有同样的问题,并希望执行真正的Android单元测试,而不是正常的JUnit测试:

您必须解除

<dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.8.1</version> 
     <!-- scope is compile, not test! --> 
     <scope>compile</scope> 
</dependency> 

JUnit的依赖和使用正常范围(编译),不测试!

希望有所帮助。

相关问题