2015-08-26 14:16:05 -07:00
|
|
|
page.title=Testing from the Command-Line
|
|
|
|
|
2010-05-07 21:30:44 -07:00
|
|
|
@jd:body
|
|
|
|
|
|
|
|
<div id="qv-wrapper">
|
2010-10-10 13:20:12 -07:00
|
|
|
<div id="qv">
|
|
|
|
<h2>In this document</h2>
|
|
|
|
<ol>
|
|
|
|
<li>
|
|
|
|
<a href="#RunTestsCommand">Running Tests</a>
|
|
|
|
<ol>
|
|
|
|
<li>
|
2015-08-26 14:16:05 -07:00
|
|
|
<a href="#RunTestsGradle">Running unit tests with Gradle</a>
|
2010-10-10 13:20:12 -07:00
|
|
|
</li>
|
|
|
|
<li>
|
2015-08-26 14:16:05 -07:00
|
|
|
<a href="#RunTestsDevice">Running tests with adb</a>
|
2010-10-10 13:20:12 -07:00
|
|
|
</li>
|
|
|
|
</ol>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a href="#AMSyntax">Using the Instrument Command</a>
|
|
|
|
<ol>
|
|
|
|
<li>
|
|
|
|
<a href="#AMOptionsSyntax">Instrument options</a>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a href="#RunTestExamples">Instrument examples</a>
|
|
|
|
</li>
|
|
|
|
</ol>
|
|
|
|
</li>
|
|
|
|
</ol>
|
|
|
|
<h2>See Also</h2>
|
|
|
|
<ol>
|
|
|
|
<li>
|
2012-06-21 17:14:39 -07:00
|
|
|
<a href="{@docRoot}tools/help/adb.html">Android Debug Bridge</a>
|
2010-10-10 13:20:12 -07:00
|
|
|
</li>
|
|
|
|
</ol>
|
|
|
|
</div>
|
2010-05-07 21:30:44 -07:00
|
|
|
</div>
|
|
|
|
<p>
|
2015-08-26 14:16:05 -07:00
|
|
|
This document describes how to create and run tests directly from the command line. This
|
|
|
|
document assumes that you already know how to create a Android application in your programming
|
|
|
|
environment.
|
2010-05-07 21:30:44 -07:00
|
|
|
</p>
|
2015-08-26 14:16:05 -07:00
|
|
|
|
|
|
|
<h2 id="RunTestsCommand">Running Tests</h2>
|
2010-05-07 21:30:44 -07:00
|
|
|
<p>
|
2015-08-26 14:16:05 -07:00
|
|
|
You can run tests from the command-line, either with Gradle or with an
|
|
|
|
<a href="{@docRoot}tools/help/adb.html">
|
|
|
|
Android Debug Bridge (adb)</a> shell.
|
2010-05-07 21:30:44 -07:00
|
|
|
</p>
|
2015-08-26 14:16:05 -07:00
|
|
|
<h3 id="RunTestsGradle">Running unit tests with Gradle</h3>
|
|
|
|
|
|
|
|
<p>The <a href="{@docRoot}tools/building/plugin-for-gradle.html">Android Plugin for Gradle</a>
|
|
|
|
lets you run unit tests from your Gradle project via the command-line. For more information on
|
|
|
|
how to build unit tests for your app, see
|
|
|
|
<a href="{@docRoot}training/testing/unit-testing/index.html">Building Effective Unit Tests</a>.</p>
|
|
|
|
|
|
|
|
<p>The table below summarizes how to run your unit tests with Gradle:</p>
|
2010-05-07 21:30:44 -07:00
|
|
|
<table>
|
2010-10-10 13:20:12 -07:00
|
|
|
<tr>
|
2015-08-26 14:16:05 -07:00
|
|
|
<th>Unit Test Type</th>
|
|
|
|
<th>Command To Run</th>
|
|
|
|
<th>Test Result Location</th>
|
2010-10-10 13:20:12 -07:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2015-08-26 14:16:05 -07:00
|
|
|
<td>Local unit test</td>
|
|
|
|
<td>Call the {@code test} task:
|
|
|
|
<pre>
|
|
|
|
./gradlew test
|
|
|
|
</pre></td>
|
|
|
|
<td>
|
|
|
|
HTML test result files:
|
|
|
|
{@code <path_to_your_project>/app/build/reports/tests/} directory.
|
|
|
|
<p>XML test result files:
|
|
|
|
{@code <path_to_your_project>/app/build/test-results/} directory.
|
|
|
|
</p></td>
|
2010-10-10 13:20:12 -07:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2015-08-26 14:16:05 -07:00
|
|
|
<td>Instrumented unit test</td>
|
|
|
|
<td>Call the {@code connectedAndroidTest} (or {@code cAT}) task:
|
2010-05-07 21:30:44 -07:00
|
|
|
<pre>
|
2015-08-26 14:16:05 -07:00
|
|
|
./gradlew cAT
|
2010-05-07 21:30:44 -07:00
|
|
|
</pre>
|
2010-10-10 13:20:12 -07:00
|
|
|
</td>
|
|
|
|
<td>
|
2015-08-26 14:16:05 -07:00
|
|
|
HTML test result files:
|
|
|
|
{@code <path_to_your_project>/app/build/outputs/reports/androidTests/connected/} directory.
|
|
|
|
<p>XML test result files:
|
|
|
|
{@code <path_to_your_project>/app/build/outputs/androidTest-results/connected/} directory.
|
|
|
|
</p></td>
|
2010-10-10 13:20:12 -07:00
|
|
|
</tr>
|
2010-05-07 21:30:44 -07:00
|
|
|
</table>
|
|
|
|
|
2015-08-26 14:16:05 -07:00
|
|
|
<h3 id="RunTestsDevice">Running tests with ADB</h3>
|
2010-05-07 21:30:44 -07:00
|
|
|
<p>
|
2015-08-26 14:16:05 -07:00
|
|
|
When you run tests from the command-line with
|
2012-06-21 17:14:39 -07:00
|
|
|
<a href="{@docRoot}tools/help/adb.html">
|
2010-10-10 13:20:12 -07:00
|
|
|
Android Debug Bridge (adb)</a>, you get more options for choosing the tests
|
|
|
|
to run than with any other method. You can select individual test methods, filter tests
|
|
|
|
according to their annotation, or specify testing options. Since the test run is controlled
|
2015-08-26 14:16:05 -07:00
|
|
|
entirely from a command-line, you can customize your testing with shell scripts in various ways.
|
2010-10-10 13:20:12 -07:00
|
|
|
</p>
|
|
|
|
<p>
|
2015-08-26 14:16:05 -07:00
|
|
|
To run a test from the command-line, you run <code>adb shell</code> to start a command-line
|
2010-10-10 13:20:12 -07:00
|
|
|
shell on your device or emulator, and then in the shell run the <code>am instrument</code>
|
|
|
|
command. You control <code>am</code> and your tests with command-line flags.
|
2010-05-07 21:30:44 -07:00
|
|
|
</p>
|
|
|
|
<p>
|
2010-10-10 13:20:12 -07:00
|
|
|
As a shortcut, you can start an <code>adb</code> shell, call <code>am instrument</code>, and
|
|
|
|
specify command-line flags all on one input line. The shell opens on the device or emulator,
|
2015-08-26 14:16:05 -07:00
|
|
|
runs your tests, produces output, and then returns to the command-line on your computer.
|
2010-05-07 21:30:44 -07:00
|
|
|
</p>
|
|
|
|
<p>
|
2010-10-10 13:20:12 -07:00
|
|
|
To run a test with <code>am instrument</code>:
|
2010-05-07 21:30:44 -07:00
|
|
|
</p>
|
|
|
|
<ol>
|
2010-10-10 13:20:12 -07:00
|
|
|
<li>
|
|
|
|
If necessary, rebuild your main application and test package.
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
Install your test package and main application Android package files
|
|
|
|
(<code>.apk</code> files) to your current Android device or emulator</li>
|
|
|
|
<li>
|
2015-08-26 14:16:05 -07:00
|
|
|
At the command-line, enter:
|
2010-05-07 21:30:44 -07:00
|
|
|
<pre>
|
|
|
|
$ adb shell am instrument -w <test_package_name>/<runner_class>
|
|
|
|
</pre>
|
2010-10-10 13:20:12 -07:00
|
|
|
<p>
|
|
|
|
where <code><test_package_name></code> is the Android package name of your test
|
|
|
|
application, and <code><runner_class></code> is the name of the Android test
|
|
|
|
runner class you are using. The Android package name is the value of the
|
|
|
|
<code>package</code> attribute of the <code>manifest</code> element in the manifest file
|
|
|
|
(<code>AndroidManifest.xml</code>) of your test package. The Android test runner
|
2015-08-26 14:16:05 -07:00
|
|
|
class is usually
|
|
|
|
<a href="{@docRoot}reference/android/support/test/runner/AndroidJUnitRunner.html">
|
|
|
|
{@code AndroidJUnitRunner}</a>.
|
2010-10-10 13:20:12 -07:00
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
Your test results appear in <code>STDOUT</code>.
|
|
|
|
</p>
|
|
|
|
</li>
|
2010-05-07 21:30:44 -07:00
|
|
|
</ol>
|
|
|
|
<p>
|
2010-10-10 13:20:12 -07:00
|
|
|
This operation starts an <code>adb</code> shell, then runs <code>am instrument</code>
|
2010-05-07 21:30:44 -07:00
|
|
|
with the specified parameters. This particular form of the command will run all of the tests
|
2010-10-10 13:20:12 -07:00
|
|
|
in your test package. You can control this behavior with flags that you pass to
|
2010-05-07 21:30:44 -07:00
|
|
|
<code>am instrument</code>. These flags are described in the next section.
|
|
|
|
</p>
|
2010-10-10 13:20:12 -07:00
|
|
|
<h2 id="AMSyntax">Using the am instrument Command</h2>
|
2010-05-07 21:30:44 -07:00
|
|
|
<p>
|
2010-10-10 13:20:12 -07:00
|
|
|
The general syntax of the <code>am instrument</code> command is:
|
2010-05-07 21:30:44 -07:00
|
|
|
</p>
|
|
|
|
<pre>
|
2015-08-26 14:16:05 -07:00
|
|
|
am instrument [flags] <test_package>/<runner_class>
|
2010-05-07 21:30:44 -07:00
|
|
|
</pre>
|
|
|
|
<p>
|
|
|
|
The main input parameters to <code>am instrument</code> are described in the following table:
|
|
|
|
</p>
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<th>
|
|
|
|
Parameter
|
|
|
|
</th>
|
|
|
|
<th>
|
|
|
|
Value
|
|
|
|
</th>
|
|
|
|
<th>
|
|
|
|
Description
|
|
|
|
</th>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
<code><test_package></code>
|
|
|
|
</td>
|
|
|
|
<td>
|
2010-10-10 13:20:12 -07:00
|
|
|
The Android package name of the test package.
|
2010-05-07 21:30:44 -07:00
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
The value of the <code>package</code> attribute of the <code>manifest</code>
|
2010-10-10 13:20:12 -07:00
|
|
|
element in the test package's manifest file.
|
2010-05-07 21:30:44 -07:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
<code><runner_class></code>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
The class name of the instrumented test runner you are using.
|
|
|
|
</td>
|
|
|
|
<td>
|
2015-08-26 14:16:05 -07:00
|
|
|
This is usually
|
|
|
|
<a href="{@docRoot}reference/android/support/test/runner/AndroidJUnitRunner.html">
|
|
|
|
{@code AndroidJUnitRunner}</a>.
|
2010-05-07 21:30:44 -07:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
2015-08-26 14:16:05 -07:00
|
|
|
|
2010-05-07 21:30:44 -07:00
|
|
|
<p>
|
2010-10-10 13:20:12 -07:00
|
|
|
The flags for <code>am instrument</code> are described in the following table:
|
2010-05-07 21:30:44 -07:00
|
|
|
</p>
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<th>
|
|
|
|
Flag
|
|
|
|
</th>
|
|
|
|
<th>
|
|
|
|
Value
|
|
|
|
</th>
|
|
|
|
<th>
|
|
|
|
Description
|
|
|
|
</th>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
<code>-w</code>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
(none)
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
Forces <code>am instrument</code> to wait until the instrumentation terminates
|
|
|
|
before terminating itself. The net effect is to keep the shell open until the tests
|
|
|
|
have finished. This flag is not required, but if you do not use it, you will not
|
|
|
|
see the results of your tests.
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
<code>-r</code>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
(none)
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
Outputs results in raw format. Use this flag when you want to collect
|
|
|
|
performance measurements, so that they are not formatted as test results. This flag is
|
|
|
|
designed for use with the flag <code>-e perf true</code> (documented in the section
|
|
|
|
<a href="#AMOptionsSyntax">Instrument options</a>).
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
<code>-e</code>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<test_options>
|
|
|
|
</td>
|
|
|
|
<td>
|
2010-10-10 13:20:12 -07:00
|
|
|
Provides testing options as key-value pairs. The
|
2010-05-07 21:30:44 -07:00
|
|
|
<code>am instrument</code> tool passes these to the specified instrumentation class
|
|
|
|
via its <code>onCreate()</code> method. You can specify multiple occurrences of
|
2010-10-10 13:20:12 -07:00
|
|
|
<code>-e <test_options></code>. The keys and values are described in the
|
2015-08-26 14:16:05 -07:00
|
|
|
section <a href="#AMOptionsSyntax">am instrument options</a>. You can only use these
|
|
|
|
key-value pairs with
|
|
|
|
<a href="{@docRoot}reference/android/support/test/runner/AndroidJUnitRunner.html">
|
|
|
|
{@code AndroidJUnitRunner}</a> or with {@link android.test.InstrumentationTestRunner} and its
|
|
|
|
subclasses. Using them with any other class has no effect.
|
2010-05-07 21:30:44 -07:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
2010-10-10 13:20:12 -07:00
|
|
|
<h3 id="AMOptionsSyntax">am instrument options</h3>
|
2010-05-07 21:30:44 -07:00
|
|
|
<p>
|
|
|
|
The <code>am instrument</code> tool passes testing options to
|
2015-08-26 14:16:05 -07:00
|
|
|
<a href="{@docRoot}reference/android/support/test/runner/AndroidJUnitRunner.html">
|
|
|
|
{@code AndroidJUnitRunner}</a> or {@link android.test.InstrumentationTestRunner} in the form of
|
|
|
|
key-value pairs, using the <code>-e</code> flag, with this syntax:
|
2010-05-07 21:30:44 -07:00
|
|
|
</p>
|
|
|
|
<pre>
|
2015-08-26 14:16:05 -07:00
|
|
|
-e <key> <value>
|
2010-05-07 21:30:44 -07:00
|
|
|
</pre>
|
|
|
|
<p>
|
2010-10-10 13:20:12 -07:00
|
|
|
Some keys accept multiple values. You specify multiple values in a comma-separated list.
|
2015-08-26 14:16:05 -07:00
|
|
|
For example, this invocation of
|
|
|
|
<a href="{@docRoot}reference/android/support/test/runner/AndroidJUnitRunner.html">
|
|
|
|
{@code AndroidJUnitRunner}</a> provides multiple values for the <code>package</code> key:
|
2010-10-10 13:20:12 -07:00
|
|
|
</p>
|
2010-05-07 21:30:44 -07:00
|
|
|
<pre>
|
2010-10-10 13:20:12 -07:00
|
|
|
$ adb shell am instrument -w -e package com.android.test.package1,com.android.test.package2 \
|
2015-08-26 14:16:05 -07:00
|
|
|
> com.android.test/android.support.test.runner.AndroidJUnitRunner
|
2010-05-07 21:30:44 -07:00
|
|
|
</pre>
|
2015-08-26 14:16:05 -07:00
|
|
|
<p>The following table lists the key-value pairs you can use with your test runner.</p>
|
2010-05-07 21:30:44 -07:00
|
|
|
<table>
|
2010-10-10 13:20:12 -07:00
|
|
|
<tr>
|
|
|
|
<th>Key</th>
|
|
|
|
<th>Value</th>
|
|
|
|
<th>Description</th>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
<code>package</code>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<Java_package_name>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
The fully-qualified <em>Java</em> package name for one of the packages in the test
|
|
|
|
application. Any test case class that uses this package name is executed. Notice that
|
|
|
|
this is not an <em>Android</em> package name; a test package has a single
|
|
|
|
Android package name but may have several Java packages within it.
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td rowspan="2"><code>class</code></td>
|
|
|
|
<td><class_name></td>
|
|
|
|
<td>
|
|
|
|
The fully-qualified Java class name for one of the test case classes. Only this test
|
|
|
|
case class is executed.
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><class_name><strong>#</strong>method name</td>
|
|
|
|
<td>
|
|
|
|
A fully-qualified test case class name, and one of its methods. Only this method is
|
|
|
|
executed. Note the hash mark (#) between the class name and the method name.
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><code>func</code></td>
|
|
|
|
<td><code>true</code></td>
|
|
|
|
<td>
|
|
|
|
Runs all test classes that extend {@link android.test.InstrumentationTestCase}.
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><code>unit</code></td>
|
|
|
|
<td><code>true</code></td>
|
|
|
|
<td>
|
|
|
|
Runs all test classes that do <em>not</em> extend either
|
|
|
|
{@link android.test.InstrumentationTestCase} or
|
|
|
|
{@link android.test.PerformanceTestCase}.
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><code>size</code></td>
|
|
|
|
<td>
|
|
|
|
[<code>small</code> | <code>medium</code> | <code>large</code>]
|
|
|
|
</td>
|
|
|
|
<td>
|
2015-08-26 14:16:05 -07:00
|
|
|
Runs a test method annotated by size. The annotations are <code>@SmallTest</code>,
|
|
|
|
<code>@MediumTest</code>, and <code>@LargeTest</code>.
|
2010-10-10 13:20:12 -07:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><code>perf</code></td>
|
|
|
|
<td><code>true</code></td>
|
|
|
|
<td>
|
|
|
|
Runs all test classes that implement {@link android.test.PerformanceTestCase}.
|
|
|
|
When you use this option, also specify the <code>-r</code> flag for
|
|
|
|
<code>am instrument</code>, so that the output is kept in raw format and not
|
|
|
|
re-formatted as test results.
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><code>debug</code></td>
|
|
|
|
<td><code>true</code></td>
|
|
|
|
<td>
|
|
|
|
Runs tests in debug mode.
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><code>log</code></td>
|
|
|
|
<td><code>true</code></td>
|
|
|
|
<td>
|
|
|
|
Loads and logs all specified tests, but does not run them. The test
|
|
|
|
information appears in <code>STDOUT</code>. Use this to verify combinations of other
|
|
|
|
filters and test specifications.
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><code>emma</code></td>
|
|
|
|
<td><code>true</code></td>
|
|
|
|
<td>
|
|
|
|
Runs an EMMA code coverage analysis and writes the output to
|
2015-08-26 14:16:05 -07:00
|
|
|
<code>/data/<app_package>/coverage.ec</code> on the device. To override the
|
|
|
|
file location, use the <code>coverageFile</code> key that is described in the
|
|
|
|
following entry.
|
2010-10-10 13:20:12 -07:00
|
|
|
<p class="note">
|
|
|
|
<strong>Note:</strong> This option requires an EMMA-instrumented build of the test
|
|
|
|
application, which you can generate with the <code>coverage</code> target.
|
|
|
|
</p>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><code>coverageFile</code></td>
|
|
|
|
<td><code><filename></code></td>
|
|
|
|
<td>
|
|
|
|
Overrides the default location of the EMMA coverage file on the device. Specify this
|
|
|
|
value as a path and filename in UNIX format. The default filename is described in the
|
|
|
|
entry for the <code>emma</code> key.
|
|
|
|
</td>
|
|
|
|
</tr>
|
2010-05-07 21:30:44 -07:00
|
|
|
</table>
|
|
|
|
<strong><code>-e</code> Flag Usage Notes</strong>
|
|
|
|
<ul>
|
|
|
|
<li>
|
|
|
|
<code>am instrument</code> invokes
|
|
|
|
{@link android.test.InstrumentationTestRunner#onCreate(Bundle)}
|
|
|
|
with a {@link android.os.Bundle} containing the key-value pairs.
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
The <code>package</code> key takes precedence over the <code>class</code> key. If you
|
|
|
|
specifiy a package, and then separately specify a class within that package, Android
|
|
|
|
will run all the tests in the package and ignore the <code>class</code> key.
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
The <code>func</code> key and <code>unit</code> key are mutually exclusive.
|
|
|
|
</li>
|
|
|
|
</ul>
|
2010-10-10 13:20:12 -07:00
|
|
|
<h3 id="RunTestExamples">Usage examples</h3>
|
2010-05-07 21:30:44 -07:00
|
|
|
<p>
|
2010-10-10 13:20:12 -07:00
|
|
|
The following sections provide examples of using <code>am instrument</code> to run tests.
|
|
|
|
They are based on the following structure:</p>
|
2010-05-07 21:30:44 -07:00
|
|
|
<ul>
|
|
|
|
<li>
|
2010-10-10 13:20:12 -07:00
|
|
|
The test package has the Android package name <code>com.android.demo.app.tests</code>
|
2010-05-07 21:30:44 -07:00
|
|
|
</li>
|
|
|
|
<li>
|
2015-08-26 14:16:05 -07:00
|
|
|
Two instrumented test classes:
|
2010-05-07 21:30:44 -07:00
|
|
|
<ul>
|
2015-08-26 14:16:05 -07:00
|
|
|
<li>{@code Foo1} which contains the test method {@code bar1}, and</li>
|
|
|
|
<li>{@code Foo2} which contains test methods {@code bar2} and {@code bar3}</li>
|
2010-05-07 21:30:44 -07:00
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
<li>
|
2015-08-26 14:16:05 -07:00
|
|
|
The test runner is
|
|
|
|
<a href="{@docRoot}reference/android/support/test/runner/AndroidJUnitRunner.html">
|
|
|
|
{@code AndroidJUnitRunner}</a>.
|
2010-05-07 21:30:44 -07:00
|
|
|
</li>
|
|
|
|
</ul>
|
2010-10-10 13:20:12 -07:00
|
|
|
<h4>Running the entire test package</h4>
|
2010-05-07 21:30:44 -07:00
|
|
|
<p>
|
2010-10-10 13:20:12 -07:00
|
|
|
To run all of the test classes in the test package, enter:
|
2010-05-07 21:30:44 -07:00
|
|
|
</p>
|
|
|
|
<pre>
|
2015-08-26 14:16:05 -07:00
|
|
|
$ adb shell am instrument -w com.android.demo.app.tests/android.support.test.runner.AndroidJUnitRunner
|
2010-05-07 21:30:44 -07:00
|
|
|
</pre>
|
2010-10-10 13:20:12 -07:00
|
|
|
<h4>Running all tests in a test case class</h4>
|
2010-05-07 21:30:44 -07:00
|
|
|
<p>
|
|
|
|
To run all of the tests in the class <code>UnitTests</code>, enter:
|
|
|
|
</p>
|
|
|
|
<pre>
|
|
|
|
$ adb shell am instrument -w \
|
2015-08-26 14:16:05 -07:00
|
|
|
> -e class com.android.demo.app.tests.Foo \
|
|
|
|
> com.android.demo.app.tests/android.support.test.runner.AndroidJUnitRunner
|
2010-05-07 21:30:44 -07:00
|
|
|
</pre>
|
|
|
|
<p>
|
|
|
|
<code>am instrument</code> gets the value of the <code>-e</code> flag, detects the
|
|
|
|
<code>class</code> keyword, and runs all the methods in the <code>UnitTests</code> class.
|
|
|
|
</p>
|
2010-10-10 13:20:12 -07:00
|
|
|
<h4>Selecting a subset of tests</h4>
|
2010-05-07 21:30:44 -07:00
|
|
|
<p>
|
2015-08-26 14:16:05 -07:00
|
|
|
To run all of the tests in <code>Foo1</code>, and the <code>bar3</code> method in
|
|
|
|
<code>Foo2</code>, enter:
|
2010-05-07 21:30:44 -07:00
|
|
|
</p>
|
|
|
|
<pre>
|
|
|
|
$ adb shell am instrument -w \
|
2015-08-26 14:16:05 -07:00
|
|
|
> -e class com.android.demo.app.tests.Foo1,com.android.demo.app.tests.Foo2#bar3 \
|
|
|
|
> com.android.demo.app.tests/android.support.test.runner.AndroidJUnitRunner
|
2010-05-07 21:30:44 -07:00
|
|
|
</pre>
|