【问题标题】:android-maven-plugin, instrumentation testing and testSizeandroid-maven-plugin,仪器测试和 testSize
【发布时间】:2012-07-05 15:05:46
【问题描述】:

我正在使用 maven 来构建、运行和检测我的 Android 应用程序。 Android 测试框架有@SmallTest@MediumTest@LargeTest 三个不同的测试范围,android-maven-plugin 可以通过testTestSizetest/testSize 参数选择测试范围。此参数可以是small|medium|large 之一,并且可以从相关范围运行您的测试。

但是,如果我想同时运行小型和中型测试,不仅是小型测试还是中型测试,我该怎么办?有解决这个问题的办法吗?

【问题讨论】:

    标签: android maven integration-testing instrumentation android-maven-plugin


    【解决方案1】:

    根据InstrumentationTestRunner API doc,这就是目前 Android SDK 的设计和工作方式:

    运行所有小测试: adb shell am instrument -w -e size small com.android.foo/android.test.InstrumentationTestRunner

    运行所有中等测试: adb shell am instrument -w -e size medium com.android.foo/android.test.InstrumentationTestRunner

    运行所有大型测试: adb shell am instrument -w -e size large com.android.foo/android.test.InstrumentationTestRunner

    即使你使用普通的 adb 命令运行你的测试,你也必须使用两个进程分别运行中小型测试,一个接一个。 Android Maven 插件只是 adb 命令的另一个包装器,因此无法通过 android-maven-plugin 配置 AFAIK 更改默认行为。


    如果你仔细阅读InstrumentationTestRunner API doc,你会注意到有一个有趣的命令用法:

    使用给定注释过滤测试运行: adb shell am instrument -w -e annotation com.android.foo.MyAnnotation com.android.foo/android.test.InstrumentationTestRunner

    如果与其他选项一起使用,生成的测试运行将包含两个选项的并集。例如"-e size large -e annotation com.android.foo.MyAnnotation" 将只运行带有 LargeTest 和 "com.android.foo.MyAnnotation" 注释的测试。

    注释配置被添加为实验性 API(标记为 @hide,有关更多详细信息,请查看 this version history),并且尚未在 am instrument options list 中记录。从理论上讲,您可以创建自己的注释类(参见SmallTest.java 作为示例),将所有@MediumTest 与@CustomizedTest 一起标记并使用-e size 和-e 注释来实现您想要的:同时从两个注释运行联合测试,一站式服务。

    很遗憾,android-maven-plugin 不支持注解配置,参见plugin documentationlatest source code。一种可能的解决方法是使用 exec-maven-plugin 运行普通的adb shell am instrument 命令。

    希望这是有道理的。

    【讨论】:

      【解决方案2】:

      为了使用 maven-android 的测试大小,我在 pom.xml 中创建了一个变量:

      ...
      <properties>
        <config.build.testSize>medium</config.build.testSize>
      </properties>
      ...
      

      在构建中,如下:

      <build>  
       <pluginManagement>
        <plugins>
         <plugin>
          <groupId>com.jayway.maven.plugins.android.generation2</groupId>
          <artifactId>android-maven-plugin</artifactId>
          ...
          <configuration>
           <test>
            <testSize>${config.build.testSize}</testSize>
           </test>
          </configuration>
          ...
         </plugin>
        </plugins>
       </pluginManagement> 
      </build>
      

      我假设,您也可以通过向 maven 提供 android.test.testSize 参数来实现这一点(例如 mvn install -Dandroid.test.testSize=medium)

      如果我错了,请更正这个 maven 变量,在文档中还没有找到。 BR, M.

      【讨论】:

        猜你喜欢
        • 2011-08-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-27
        • 1970-01-01
        • 1970-01-01
        • 2014-05-22
        相关资源
        最近更新 更多