---
title: "使用命令行在手机上运行android单元测试"
author: "nid007"
date: "2014-07-03T10:25:59Z"
tags: []
categories: ["移动开发"]
slug: "android"
draft: false
lastmod: "2014-07-03T10:25:59Z"
id: 2087823
url: "https://nid007.iteye.com/blog/2087823"
---

本文假设你已经知道如何adb连接设备，知道如何在eclipse里运行android的单元测试。

关键命令：

```shell

直接运行所有有case
adb shell am instrument -w com.myapp.test/android.test.InstrumentationTestRunner

运行一个case
adb shell am instrument -w -e class com.myapp.test.TestDemo#testSearch com.myapp.test/android.test.InstrumentationTestRunner

```


说明：com.myapp.test是包名，com.myapp.test.TestDemo是类名 testSearch是方法名

更多信息可以参考官网：
http://developer.android.com/tools/testing/testing_otheride.html#RunTestsDevice