首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >android-maven-plugin、工具测试和testSize

android-maven-plugin、工具测试和testSize
EN

Stack Overflow用户
提问于 2012-07-05 23:05:46
回答 2查看 843关注 0票数 4

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

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-07-10 19:01:16

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

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

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

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

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

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

使用给定注释对测试运行

Filter测试: adb shell am instrument -w -e annotation com.android.foo.MyAnnotation shell

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

注释配置被添加为实验应用程序接口(标记为@hide,有关更多详细信息,请查看this version history),并且在am instrument options list中没有文档记录。理论上,您可以创建自己的注解类(例如SmallTest.java ),标记所有@MediumTest和@CustomizedTest,并使用-e大小和-e注解来实现您想要的结果:同时从两个注解运行联合测试,所有操作都在一个命令中完成。

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

希望这是有意义的。

票数 3
EN

Stack Overflow用户

发布于 2012-07-10 21:52:35

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

代码语言:javascript
复制
...
<properties>
  <config.build.testSize>medium</config.build.testSize>
</properties>
...

在构建过程中,如下所示:

代码语言:javascript
复制
<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.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11347158

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档