我几天来一直在抨击我,所以我觉得是时候问了。
我有一个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 lib?但我已经在依赖性中拥有了这一点。
如果有人可以帮助/提示我解决这个烂摊子,我将非常感激!
答案 0 :(得分: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依赖并使用正常范围(编译),而不是测试!
希望有所帮助。
答案 1 :(得分:0)
好的,我的表现就是这样。
我最初在一个单独的模块/ eclipse项目中有我的测试用例。这似乎在推动我的事情。
将类移到src / main / test下的主应用程序项目中,现在解决了我的所有问题,谢谢!