如何使用Eclipse将android测试框架espresso设置为Maven项目?

时间:2019-06-13 09:30:42

标签: eclipse maven android-espresso

我知道,强烈建议您使用Andriod Studio的espresso框架。但是,我们将Maven项目类型用于Weband API自动化。话虽如此,我正在尝试找到一种方法来将espresso测试框架集成为Eclipse中的Maven项目。我尝试了以下不适用于我的参考。

https://mvnrepository.com/artifact/com.android.support.test.espresso

有什么办法可以做到这一点?

谢谢, 拉姆

1 个答案:

答案 0 :(得分:0)

检出具有Quality-Tools-for-AndroidMaven with Espresso integration回购。

以防万一,项目到了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>

    <parent>
        <groupId>com.octo.android</groupId>
        <artifactId>android-sample-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>android-sample-espresso-tests</artifactId>
    <packaging>apk</packaging>
    <name>android-sample-espresso-tests</name>

    <properties>
        <build-helper-maven-plugin.version>1.8</build-helper-maven-plugin.version>
    </properties>

    <repositories>
        <!--other repositories if any -->
        <repository>
            <id>project.local</id>
            <name>project</name>
            <url>file:${project.basedir}/repo</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>android</groupId>
            <artifactId>android</artifactId>
        </dependency>
        <dependency>
            <groupId>android.support</groupId>
            <artifactId>compatibility-v4</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.octo.android</groupId>
            <artifactId>android-sample</artifactId>
            <version>${project.version}</version>
            <type>jar</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.octo.android</groupId>
            <artifactId>android-sample</artifactId>
            <version>${project.version}</version>
            <type>apk</type>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android-espresso</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

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

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.build.directory}/generated-sources/annotations/</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-pmd-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>


    <profiles>
        <profile>
            <id>emma</id>
            <dependencies>
                <dependency>
                    <groupId>emma</groupId>
                    <artifactId>emma</artifactId>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                        <artifactId>android-maven-plugin</artifactId>
                        <configuration>
                            <test>
                                <coverage>true</coverage>
                                <createReport>true</createReport>
                            </test>
                        </configuration>
                        <extensions>true</extensions>
                        <executions>
                            <execution>
                                <id>pull-coverage</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>pull</goal>
                                </goals>
                                <configuration>
                                    <pullSource>/data/data/com.octo.android.sample/files/coverage.ec</pullSource>
                                    <pullDestination>${project.basedir}/../android-sample/target/emma/coverage.ec</pullDestination>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>spoon</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                        <artifactId>android-maven-plugin</artifactId>
                        <extensions>true</extensions>
                        <configuration>
                            <testSkip>true</testSkip>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>com.squareup.spoon</groupId>
                        <artifactId>spoon-maven-plugin</artifactId>
                        <version>${spoon.version}</version>
                        <configuration>
                            <title>Spoon Sample App</title>
                            <debug>true</debug>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>jacoco</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                        <artifactId>android-maven-plugin</artifactId>
                        <configuration>
                            <dex>
                                <!-- Required for EMMA -->
                                <noLocals>true</noLocals>
                            </dex>
                            <test>
                                <coverage>true</coverage>
                                <createReport>true</createReport>
                            </test>
                        </configuration>
                        <executions>
                            <execution>
                                <id>pull-coverage</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>pull</goal>
                                </goals>
                                <configuration>
                                    <pullSource>/data/data/com.octo.android.sample/files/coverage.ec</pullSource>
                                    <pullDestination>${project.basedir}/../android-sample/target/jacoco-it.exec</pullDestination>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>

不过,到目前为止,Google建议将Gradle用于与Android开发或测试相关的任何任务,请考虑切换到Gradle,因为这样一来,您获得社区对Maven + Espresso相关问题的支持的机会将很小。查阅How to Get Started with Espresso (Android)文章,了解如何使用Gradle快速启动Espresso。