diff --git a/docs/html/images/tools/as-launchavdm.png b/docs/html/images/tools/as-launchavdm.png index bf159810adf52..f2c7bf35adad3 100644 Binary files a/docs/html/images/tools/as-launchavdm.png and b/docs/html/images/tools/as-launchavdm.png differ diff --git a/docs/html/images/tools/as-ok.png b/docs/html/images/tools/as-ok.png new file mode 100644 index 0000000000000..244a77fe707ca Binary files /dev/null and b/docs/html/images/tools/as-ok.png differ diff --git a/docs/html/images/tools/as-wrench.png b/docs/html/images/tools/as-wrench.png new file mode 100644 index 0000000000000..5886487f233d5 Binary files /dev/null and b/docs/html/images/tools/as-wrench.png differ diff --git a/docs/html/images/training/ctl-exec-log.png b/docs/html/images/training/ctl-exec-log.png new file mode 100644 index 0000000000000..96bbb81160f1f Binary files /dev/null and b/docs/html/images/training/ctl-exec-log.png differ diff --git a/docs/html/images/training/ctl-test-results.png b/docs/html/images/training/ctl-test-results.png new file mode 100644 index 0000000000000..bb2fc93d542c1 Binary files /dev/null and b/docs/html/images/training/ctl-test-results.png differ diff --git a/docs/html/training/testing/start/index.jd b/docs/html/training/testing/start/index.jd index a4b4aea9ef017..74617b0cc64c7 100644 --- a/docs/html/training/testing/start/index.jd +++ b/docs/html/training/testing/start/index.jd @@ -6,69 +6,153 @@ page.image=images/tools/studio-main-screen.png @jd:body
You should be writing and running tests as part of your Android app development cycle. -Well-written tests can help you catch bugs early in development and give you confidence in your -code.
++ Writing and running tests are important parts of the Android app development + cycle. Well-written tests can help you catch bugs early in development and + give you confidence in your code. Using Android Studio, you can run local + unit tests or instrumented tests on a variety of physical or virtual Android + devices. You can then analyze the results and make changes to your code + without leaving the development environment. +
-To verify specific behavior in your app, and to check for consistency across different Android -devices, you can write a test case. This lesson teaches you how to build a test case using the -JUnit 4 framework and the testing APIs and tools provided by Google, and how to run your -tests.
++ Local unit tests are tests that run on your local machine, without + needing access to the Android framework or an Android device. To learn how to + develop local units tests, see Building + Local Unit Tests. +
-+ Instrumented tests are tests that run on an Android device or + emulator. These tests have access to {@link android.app.Instrumentation} + information, such as the {@link android.content.Context} for the app under + test. Instrumented tests can be used for unit, user interface (UI), or app + component integration testing. To learn how to develop instrumented tests for + your specific needs, see these additional topics: +
-Before you start writing and running your tests, you must set up your test -development environment. Android Studio provides an integrated development environment for you to -create, build, and run Android app test cases from a graphical user interface (GUI).
- -You must first download the prerequisite Android development tools before proceeding:
Based on the type of test you want to create, configure the test code source location and the - project dependencies in Android Studio as described in the following sections.
++ This lesson teaches you how to build and run your tests using using Android + Studio. If you are not using Android Studio, you can learn how to + run your tests from + the command-line. +
-Local unit tests are tests that run on your local machine, without needing access to the -Android framework or an Android device. To learn how to develop local units tests, see - -Building Local Unit Tests.
-In your Android Studio project, you must store the source files for local unit tests under a -specific source directory ({@code src/test/java}). This feature improves your project organization -by letting you group your unit tests together into a single source set.
-As with production code, you can create local unit tests for a -specific flavor or build type. Keep your unit tests in a test -source tree location that corresponds to your production source tree, such as:
++ In your Android Studio project, you must store the source files for local + unit tests under a specific source directory ({@code src/test/java}). This + improves project organization by grouping your unit tests together into a + single source set. +
+ ++ As with production code, you can create local unit tests for a specific + flavor or build type. Keep your unit tests in a test source tree location + that corresponds to your production source tree, such as: +
You'll need to configure the testing dependencies for your project to use the - standard APIs provided by the JUnit 4 framework. To simplify your local unit test development, - we recommend that you include the Mockito library if your test needs to interact with Android - dependencies. To learn more about using mock objects in your local unit tests, see - - Mocking Android dependencies.
-In the {@code build.gradle} file of your Android app module, specify your dependencies like -this:
++ You'll need to configure the testing dependencies for your project to use the + standard APIs provided by the JUnit 4 framework. If your test needs to + interact with Android dependencies, include the Mockito + library to simplify your local unit tests. To learn more about using mock + objects in your local unit tests, see + Mocking Android dependencies. +
+ ++ In your app's top-level {@code build.gradle} file, you need to specify these + libraries as dependencies: +
dependencies {
@@ -108,46 +198,43 @@ dependencies {
}
-Instrumented tests are tests that run on an Android device or emulator. These tests -have access to {@link android.app.Instrumentation} information, such as the -{@link android.content.Context} for the app under test. Instrumented tests can be used for unit, -user interface (UI), or app component integration testing. To learn how to develop instrumented -tests for your specific needs, see these additional topics: -
-In your Android Studio project, you must place the source code for your instrumentated tests under
-a specific directory (src/androidTest/java).
+ In your Android Studio project, you must place the source code for your
+ instrumentated tests under a specific directory
+ (src/androidTest/java).
-Download the Android Testing Support Library, which provides APIs that allow you to quickly build and -run instrumented test code for your apps. The Testing Support Library includes a JUnit 4 test runner -(AndroidJUnitRunner -) and APIs for functional UI tests -(Espresso and -UI Automator). To -learn how to install the library, see -Testing Support Library Setup. + Download + the Android Testing Support Library Setup, which provides APIs that allow + you to quickly build and run instrumented test code for your apps. The + Testing Support Library includes a JUnit 4 test runner (AndroidJUnitRunner + ) and APIs for functional UI tests (Espresso + and UI + Automator).
-You'll need to configure the Android testing dependencies for your project to use the test runner -and the rules APIs provided by the Testing Support Library. To simplify your test development, -we also recommend that you include the Hamcrest library, which lets you create more flexible assertions using the -Hamcrest matcher APIs.
-In the {@code build.gradle} file of your Android app module, specify your dependencies like -this:
+ ++ You'll need to configure the Android testing dependencies for your project to + use the test runner and the rules APIs provided by the Testing Support + Library. To simplify your test development, we also recommend that you + include the Hamcrest library, which lets you create more flexible + assertions using the Hamcrest matcher APIs. +
+ ++ In your app's top-level {@code build.gradle} file, you need to specify these + libraries as dependencies: +
+
dependencies {
androidTestCompile 'com.android.support:support-annotations:23.0.1'
@@ -162,59 +249,13 @@ dependencies {
}
-You can run build and run your tests in a similar way to how you run your Android apps -- - graphically in Android Studio or from the command-line using the - -Android Plugin for Gradle.
- --The Android Plugin for Gradle compiles the local unit test code located in the default directory -({@code src/test/java}), builds a test app, and executes it locally -using the default test runner class. + To use JUnit 4 test classes, make sure to specify {@code + AndroidJUnitRunner} as the default test instrumentation runner in your + project by including the following setting in your app's module-level {@code build.gradle} + file:
--To run local unit tests in your Gradle project from Android Studio: -
-Android Studio displays the results of the unit test execution in the Run -window.
- -To run local unit tests in your Gradle project from the command-line, call the {@code test} task -command.
- --./gradlew test -- -
If there are failing tests, the command will display links to HTML reports (one per build -variant). You can find the generated HTML test result reports in the -{@code <path_to_your_project>/app/build/reports/tests/} directory, and the corresponding XML -files in the {@code <path_to_your_project>/app/build/test-results/} directory.
- --The Android Plugin for Gradle compiles the instrumented test code located in the default directory -({@code src/androidTest/java}), builds a test APK and production APK, installs both APKs on the -connected device or emulator, and executes the tests.
- -Make sure to specify - -{@code AndroidJUnitRunner} as the default test instrumentation runner in your project. To do -this, add the following setting in your {@code build.gradle} file:
android {
@@ -224,29 +265,257 @@ android {
}
-To run your instrumented tests in Android Studio:
++ Android Studio provides all the tools you need to build, run, and analyze + your tests within the development environment. You can also run instrumented + tests on multiple device configurations, simultaneously, using Cloud Test Lab + integration. +
+ ++ Note: While running or debugging instrumented tests, + Android Studio does not inject the additional methods required for Instant Run + and turns the feature off. +
+ ++ To run your local unit tests: +
+Android Studio displays the results of the instrumented test execution in the -Run window.
++ The Android Plugin for Gradle compiles the local unit test code located in + the default directory ({@code src/test/java}), builds a test app, and + executes it locally using the default test runner class. Android Studio then + displays the results in the Run window. +
-To run your instrumented tests from the command-line via Gradle, call the - {@code connectedAndroidTest} (or {@code cAT}) task:
+-./gradlew cAT -+
+ To run your instrumented tests: +
-You can find the generated HTML test result reports in the -{@code <path_to_your_project>/app/build/outputs/reports/androidTests/connected/} directory, -and the corresponding XML files in the -{@code <path_to_your_project>/app/build/outputs/androidTest-results/connected/} directory.
\ No newline at end of file ++ The Android Plugin + for Gradle compiles the instrumented test code located in the default + directory ({@code src/androidTest/java}), builds a test APK and production + APK, installs both APKs on the connected device or emulator, and runs the + tests. Android Studio then displays the results of the instrumented test execution in the + Run window. +
+ ++ Using Cloud Test + Lab, you can simultaneously test your app on many popular Android + devices, across multiple languages, screen orientations, and versions of the + Android platform. These tests run on actual physical devices in remote Google + data centers. You can also configure + your instrumented tests to take screenshots while Cloud Test Lab runs its + tests. You can deploy tests to + Cloud Test Lab from the command line, or from Android Studio's integrated + testing tools. +
+ ++ Android Studio allows you to connect to your Google Cloud Platform account, + configure your tests, deploy them to Cloud Test Lab, and analyze the results + all within the development environment. Cloud Test Lab in Android Studio + supports the following Android test frameworks: Espresso, + UI + Automator 2.0, or Robotium. Test results provide + test logs and include the details of any app failures. +
+ ++ Before you can start using Cloud Test Lab, you need to: +
+ ++ Android Studio provides integrated tools that allow you to configure how you + want to deploy your tests to Cloud Test Lab. After you have created a Google + Cloud project with active billing, you can create a test configuration and + run your tests: +
+ +
.
+
+ When Cloud Test Lab completes running your tests, the Run window will
+ open to show the results, as shown in figure 1. You may need to click
+ Show Passed
to see all your executed tests.
+
+
+
+ Figure 1. Viewing the results of instrumented tests using + Cloud Test Lab. +
+ ++ You can also analyze your tests on the web by following the link displayed at + the beginning of the test execution log in the Run window, as shown + in figure 2. +
+ +
+
+
+ Figure 2. Click the link to view detailed test results on + the web. +
+ ++ To learn more about interpreting web results, see Analyzing + Cloud Test Lab Web Results. +
\ No newline at end of file