gpt4 book ai didi

java - 如何为 mavenised Android 应用程序运行集成测试?

转载 作者:搜寻专家 更新时间:2023-11-01 08:03:09 24 4
gpt4 key购买 nike

我想运行一些测试,例如检查 Activity A 在启动 Activity B 时将一些信息放入 Intent 中。

这些测试需要有 Android 基础设施。

我如何实现它们才能使用 Maven 运行它们?

我试过了

  1. 为此使用 akquinet 原型(prototype)并使用单独的 Mave 项目进行集成测试,但是 it never worked (我的 Robolectric 测试未执行)和
  2. 在与主应用程序相同的 Maven 项目中运行它们,这会导致 ClassNotFoundErrors 由 Robolectric 引起(当我将 Roboelectric 添加到依赖项时,我无法 mvn install 我的项目,因为我收到非 Robolectric 类的类路径相关错误)。

更新 1 (23.08.2013):父项目的 POM:

<?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>com.mycompany</groupId>
<artifactId>my-product-parent</artifactId>
<version>1.3.0</version>
<packaging>pom</packaging>
<name>my-product - Parent</name>

<modules>
<module>my-product</module>
<module>my-product-it</module>
</modules>

<properties>
<platform.version> 4.1.1.4
</platform.version>
<android.plugin.version>3.6.0</android.plugin.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android-test</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>${android.plugin.version}</version>
<configuration>
<sdk>
<platform>16</platform>
</sdk>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

实际应用项目的POM:

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

<parent>
<groupId>com.mycompany</groupId>
<artifactId>my-product-parent</artifactId>
<version>1.3.0</version>
</parent>

<groupId>com.mycompany</groupId>
<artifactId>my-product</artifactId>
<version>1.4.0</version>
<packaging>apk</packaging>
<name>my-product - Application</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<powermock.version>1.5</powermock.version>
</properties>

<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>some-library</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>commons</artifactId>
<version>2.5</version>
<exclusions>
<exclusion>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.1.4</version>
</dependency>
<!-- Testing (start) -->
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert-core</artifactId>
<version>2.0M8</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<scope>test</scope>

</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>

<!-- Testing (end) -->
<!-- Google Maps (start) -->
<!--
<dependency>
<groupId>com.google.android.maps</groupId>
<artifactId>maps</artifactId>
<version>16_r3</version>
<scope>provided</scope>
</dependency>


-->
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>google-play-services</artifactId>
<version>6</version>
<type>apklib</type>
</dependency>

<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>google-play-services</artifactId>
<version>6</version>
<type>jar</type>
</dependency>
<!-- Google Maps (end) -->
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>

集成测试项目的POM:

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

<parent>
<groupId>com.mycompany</groupId>
<artifactId>my-product-parent</artifactId>
<version>1.3.0</version>
</parent>

<artifactId>my-product-it</artifactId>
<packaging>apk</packaging>
<name>my-product-it - Integration tests</name>

<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android-test</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>my-product</artifactId>
<type>apk</type>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>my-product</artifactId>
<type>jar</type>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert-core</artifactId>
<version>2.0M8</version>
</dependency>

<!-- Make sure this (robolectric dependency) is below the android dependencies -->
<dependency>
<groupId>com.pivotallabs</groupId>
<artifactId>robolectric</artifactId>
<version>1.0-RC4</version>
<exclusions>
<exclusion>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</exclusion>
<exclusion>
<groupId>org.objenesis</groupId>
<artifactId>objenesis</artifactId>
</exclusion>
<!--
<exclusion>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</exclusion>
-->
</exclusions>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<test>
<!--<skip>true|false|auto</skip> -->
<!--<instrumentationPackage>packageName</instrumentationPackage> -->
`
<!--<instrumentationRunner>className</instrumentationRunner> -->
<!--<debug>true|false</debug> -->
<!--<coverage>true|false</coverage> -->
<!--<logonly>true|false</logonly> avd -->
<!--<testsize>small|medium|large</testsize> -->
<createReport>true</createReport>

<classes>
<class>com.mycompany.cb.android.test.AcceptInvitationActivityTest</class>
</classes>

<!--<classes> -->
<!--<class>your.package.name.YourTestClass</class> -->
<!--</classes> -->
<!--<packages> -->
<!--<package>your.package.name</package> -->
<!--</packages> -->
</test>
</configuration>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>

最佳答案

检查 Github Android 应用程序源代码。 https://github.com/github/android

这个项目有一个非常好的 maven 设置和集成测试。他们使用 Roboguicemaven-android-plugin

希望对您有所帮助。

关于java - 如何为 mavenised Android 应用程序运行集成测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18172753/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com