diff --git a/docs/html/images/tools/studio-test-module.png b/docs/html/images/tools/studio-test-module.png new file mode 100644 index 0000000000000..c0aa58ff0f59b Binary files /dev/null and b/docs/html/images/tools/studio-test-module.png differ diff --git a/docs/html/tools/studio/studio-features.jd b/docs/html/tools/studio/studio-features.jd index c2228010d248a..97174620434fb 100644 --- a/docs/html/tools/studio/studio-features.jd +++ b/docs/html/tools/studio/studio-features.jd @@ -14,6 +14,7 @@ page.tags=studio, features
<animated-selector>, are supported.
+Android Studio supports adding a separate test module to your app so you can
+generate a test APK. This test module resides at the same level as your app and
+contains: the tests and instrumentation used to run the test APK on an Android device; an
+Android Manifest.xml file for test APK configuration settings; and, a
+build.gradle file for build settings.
The test module cannot contain a src/androidTest/ folder and does
+not support build variants. If you have different product flavors in your main application APK,
+create a different test module for each build variant.
To create a test APK module: + +
test module consisting of the following directories and files:
+ ./test/ ./test/build.gradle ./test/src/main/java/com/android/tests/basic/MainTest.java ./test/src/main/AndroidManifest.xml build.gradle file, add the required properties to the
+ android block.
+ targetProjectPath ':<app name>' specifies the main application APK
+ to test. targetVariant ':<buildType>' specifies the target build type.Here is an example of build.gradle file property settings:
+android {
+ compileSdkVersion 19
+ buildToolsVersion = ‘21.1.3’
+
+ targetProjectPath ':app'
+ targetVariant 'debug'
+}
+
+ Here is an example of <instrumentation> settings in the manifest file:
+<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.tests.basic.test"> + + <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="16" /> + + <application> + >uses-library android:name="android.test.runner" /> + </application> + + <instrumentation android:name="android.test.InstrumentationTestRunner" + android:targetPackage="com.android.tests.basic" + android:handleProfiling="false" + android:functionalTest="false" + android:label="Tests for com.android.tests.basic"/> +</manifest< ++ +
Note: The targetPackage in the instrumentation
+settings specifies the package of the test variant.
build.gradle file for the tested app, include additional artifacts
+ that the test APK requires, such as the classes.jar file, by adding the
+ {@code publishNonDefault} property to the {@code Android} block, and assigning that property
+ a value of {@code true}.
+ Here is an example of the build.gradle file that includes additional
+ artifacts:
+android {
+ compileSdkVersion 19
+ buildToolsVersion = ‘21.1.3’
+
+ publishNonDefault true
+}
+
+
+
+
+
+In the {@code test} module in this example, the {@code build.gradle} file specifies the +properties for the project path and target build type variant.
+ +
Figure 3. Test module for APK testing.
+ + +Note: By default, the test module's build variant uses the
+debug build type. You can configure additional build types using the
+testBuildType property in the defaultConfig block in the main
+app's build.gradle file.