`
leiya172
  • 浏览: 26746 次
社区版块
存档分类
最新评论

命令中运行Android InstrumentationTestRunner 执行单个case

 
阅读更多

运行一个testcase

adb shell am instrument -e class com.cyou.cma.clauncher.test.TestSuit -w com.cyou.cma.clauncher.test/android.test.InstrumentationTestRunner

运行一个testcase中的一个方法:

adb shell am instrument -e class com.cyou.cma.clauncher.test.TestSuit#XXXX方法 -w com.cyou.cma.clauncher.test/android.test.InstrumentationTestRunner

命令解析:

start an Instrumentation: am instrument [flags] <COMPONENT>

-r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT)

-e <NAME> <VALUE>: set argument <NAME> to <VALUE>

-p <FILE>: write profiling data to <FILE>

-w: wait for instrumentation to finish before returning

-e后面加参数 class就可以指定一个测试类,里面包含了若干个测试方法。

按照android帮助文档里面的名称,testsuite包含了若干个testcase,一个testcase其实就是一个测试类。

比如:Run the instrumentation using "adb shell am instrument -w", with the argument '-e class' set to run an individual.

如果想指定只执行某一个测试方法,就需要用#testxxx.第二个命令

有时候也可以用$符号,但是有什么区别,没有去研究。

以下是一些copy来的文档,个人觉得比较有用:

在介绍具体的命令之前,我们先理解一下单元测试的层次。一组单元测试可以被组织成若干个TestSuite。每个TestSuite包含若干 TestCase(某个继承android.jar的junit.framework.TestCase的类)。每个TestCase又包含若干个 Test(具体的test方法)。

  如果假设com.android.foo是你的测试代码的包的根。当执行以下命令时,会执行所有的TestCase的所有Test。测试的对象就是在Target Package中指定的包中的代码:

  adb shell am instrument -w com.android.foo/android.test.InstrumentationTestRunner

  如果你想运行一个TestSuite,首先继承android.jar的junit.framework.TestSuite类,实现一个 TestSuite(比如叫com.android.foo.MyTestSuite),然后执行以下命令执行此TestSuite

  adb shell am instrument -e class com.android.foo.MyTestSuite -w com.android.foo/android.test.InstrumentationTestRunner

  其中的-e表示额外的参数,语法为-e [arg1] [value1] [arg2] [value2] …这里用到了class参数。

  如果仅仅想运行一个TestCase(比如叫com.android.foo.MyTestCase),则用以下命令:

  adb shell am instrument -e class com.android.foo.MyTestCase -w com.android.foo/android.test.InstrumentationTestRunner

  如果仅仅想运行一个Test(比如就是上面MyTestCase的testFoo方法),很类似的,就这样写:

  adb shell am instrument -e class com.android.foo.MyTestCase#testFoo -w com.android.foo/android.test.InstrumentationTestRunner

版权声明:本文为博主原创文章,未经博主允许不得转载。

分享到:
评论

相关推荐

    MubalooOrgChartTest:Android 测试项目(InstrumentationTestRunner)

    要运行测试项目,请使用以下命令 “adb shell am instrument -w com.mubaloo.org.chart.test.tests/android.test.InstrumentationTestRunner” 总共四个测试和一个 UI 测试。 TestHTTPProxyRequest - 测试 ...

    android-junit-report-dev

    1、 在应用tests目录文件下新建一个libs文件夹,将android-junit-...10、在应用代码根目录下(与sonar-project.properties同目录下)执行sonar-scanner命令,则可以在sonar网站中得到相关代码的覆盖率和单元测试数。

    Android 单元测试 方法

    总结个人在项目开发中进行单元测试的方法 ActivityInstrumentationTestCase2 ServiceTestCase android.test.InstrumentationTestRunner 等开发日志

    android连接SQLite数据库源代码

    &lt;instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="jll.sqlite" android:label="Tests for My App" /&gt; package jll.sqlitedb; import android.content....

    android自动化测试初探

    android自动化测试初探 InstrumentationTestRunner

    flexmojos-flex3-compatibility-layer-4.0-RC1.zip

    JUnitInstrumentationTestRunner.zip,JUnitInstrumentationTestRunner是Android InstrumentationTestRunner的扩展,它添加了

    android 学习笔记

    电话拨号 使用系统自带意图对象完成: Intent intent=new Intent(); intent.setAction(... android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.xiaoqiang" /&gt; &lt;/manifest&gt;

    DoodleDraw:实现基本涂鸦线绘制功能的演示应用程序

    涂鸦画 安装: DoodleDraw支持具有Android ...选择“ android.test.InstrumentationTestRunner”作为测试运行器。 运行配置 归因 该应用程序使用作为DI和管道框架。 请查看更多详细信息。 涂鸦愉快!

    android之Junit 深入研究

    这里是关于对android进行单元测试开发所需的一些核心类和资料,看完你就了解如何在android平台下进行测试驱动开发了

    Robotium简单示例

    也可以把两个APK都安装到手机上后,使用命令 adb shell am instrement -w com.jayway.test/android.test.InstrumentationTestRunner运行。。注意保证两个APK的签名都是使用同一个证书,否则无法运行。

    Instrumentation框架源码

    包含6个.java源码 仅供学习使用 InstrumentationCoreTestRunner InstrumentationTestCase InstrumentationTestRunner InstrumentationTestRunnerTest InstrumentationTestSuite InstrumentationUtils

Global site tag (gtag.js) - Google Analytics