【问题标题】:android-maven-plugin, instrumentation testing and testSizeandroid-maven-plugin,仪器测试和 testSize
【发布时间】:2012-07-05 15:05:46
【问题描述】:
【问题讨论】:
标签:
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 documentation 和latest 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.