0

几天来我一直在抨击这个问题,所以我想是时候问了。

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

所以现在我将继续通过 maven 使用这些测试,这样我就可以将它们用于 CI。

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

主 POM。

<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>

测试项目位于测试项目中的 main/java/... 下

当我编译时,我使用 mvn clean test

它抛出的错误是

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 库?但我已经在dependancioes中拥有它。

如果有人可以帮助/提示我解决这个烂摊子,将不胜感激!

4

2 回答 2

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 依赖并使用正常范围(编译),而不是测试!

希望有帮助。

于 2015-03-12T09:51:06.477 回答
0

好的,这就是我的做法。

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

将类移动到 src/main/test 下的主应用程序项目中,这现在解决了我所有的问题,谢谢!

于 2013-01-10T12:19:47.893 回答