[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-03-26 UTC。"],[],[],null,["# Complex test configuration\n\n| **Important:** The instructions on this page are needed only for Android [Compatibility Test Suite](/docs/compatibility/cts) (CTS) tests or those that require special setup, such as disabling Bluetooth or collecting sample data. All other cases can be covered by the Soong-based [Simple Test\n| Configuration](/docs/core/tests/development/blueprints) using Blueprints that automate much of the configuration previously conducted manually.\n\nSome test modules may require customized setup and tear down steps that cannot\nbe performed within the test case itself. Typical examples may include:\n\n- install other apks (in addition to the test apk)\n- push some files to the device\n- run commands (e.g. adb shell pm ...)\n\nIn the past, component teams usually resort to writing a host side test to\nperform such tasks, which requires understanding of Trade Federation harness\nand typically increases the complexity of a test module .\n\nBorrowing from CTS, we introduced the concept of test module config to support\nsuch tasks, the common tasks list above can be achieved by just a few lines of\nconfig. For maximum flexibility, you can even implement your own target\npreparer, as defined by [ITargetPreparer](/reference/com/android/tradefed/targetprep/ITargetPreparer)\nor [ITargetCleaner](/reference/com/android/tradefed/targetprep/ITargetCleaner),\nand configure them to use in your own test module config.\n\nA test module config for a test module is a required XML file added to the top\nlevel module source folder, named 'AndroidTest.xml'. The XML follows the format\nof a configuration file used by Trade Federation test automation harness.\nCurrently the main tags handled via the test module configs are the \"target_preparer\" and\n\"test\" tags.\n\nTarget preparers\n----------------\n\nA \"target_preparer\" tag, as the name suggests, defines a target preparer\n(see [ITargetPreparer](/reference/com/android/tradefed/targetprep/ITargetPreparer))\nthat offers a setup method, which gets called before the test module is executed\nfor testing; and if the class referenced in the \"target_preparer\" tag also\nimplements\n[ITargetCleaner](/reference/com/android/tradefed/targetprep/ITargetCleaner),\nits teardown method will be invoked after the test module has finished.\n\nTo use the built-in common module config, add a new file 'AndroidTest.xml' at\nthe top level folder for your test module, and populate it with the following\ncontent: \n\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003c!-- [insert standard AOSP copyright here] --\u003e\n \u003cconfiguration description=\"Test module config for Foo\"\u003e\n \u003c!-- insert options here --\u003e\n \u003c/configuration\u003e\n\nAs an example, we can add the following option tags (at the \"insert\" comment\nabove): \n\n \u003ctarget_preparer class=\"com.android.tradefed.targetprep.RunCommandTargetPreparer\"\u003e\n \u003coption name=\"run-command\" value=\"settings put secure accessibility_enabled 1\" /\u003e\n \u003coption name=\"teardown-command\" value=\"settings put secure accessibility_enabled 0\" /\u003e\n \u003c/target_preparer\u003e\n\nThe options will configure the test harness to:\n\n1. before test module is invoked, execute shell command \"settings put secure accessibility_enabled 1\" on device\n2. after test module is finished, execute shell command \"settings put secure accessibility_enabled 0\"\n\nIn this particular example, accessibility is enabled/disabled before/after the\ntest module execution, respectively. With a simple example demonstrated, it's\nnecessary to cover more details on how the \"option\" tag is used. As shown above,\nthe tag can have two attributes: name, value. The name attribute must refer to\none of the options offered by the preparer.\n\nThe exact purpose of value field is dependent on how preparer defined\nthe option: it can be a string, a number, a boolean, or even a file path.\nHere's a summary of the three common target preparers:\n\n- class name: [PushFilePreparer](https://android.googlesource.com/platform/tools/tradefederation/+/android16-release/test_framework/com/android/tradefed/targetprep/PushFilePreparer.java)\n\n - **short name**: push-file\n - **function**: pushes arbitrary files under test case folder into destination on device\n - **notes** :\n - this preparer can push from folder to folder, or file to file; that is, you cannot push a file under a folder on device: you must specify the destination filename under that folder as well\n - **options** :\n - **push-file:** A push-spec, specifying the local file to the path where it should be pushed on device. May be repeated. If multiple files are configured to be pushed to the same remote path, the latest one will be pushed.\n - **push:** *(deprecated)* A push-spec, formatted as '`/path/to/srcfile.txt-\u003e/path/to/destfile.txt`' or '`/path/to/srcfile.txt-\u003e/path/to/destdir/`'. May be repeated. This path may be relative to the test module directory or the out directory itself.\n - **post-push:** A command to run on the device (with \\``adb shell\n \u003cyour command\u003e`\\`) after all pushes have been attempted. Typical use case would be using chmod for permissions\n- class name: [InstallApkSetup](https://android.googlesource.com/platform/tools/tradefederation/+/android16-release/test_framework/com/android/tradefed/targetprep/InstallApkSetup.java)\n\n - **short name:**install-apk\n - **function:** pushes arbitrary apk files under into destination on device\n - **options:**\n - **test-file-name:** the name of the apk to be installed on to device.\n - **install-arg:** Additional arguments to be passed to the pm install command, including leading dash, e.g. \"-d\". May be repeated\n- class name: [RunCommandTargetPreparer](https://android.googlesource.com/platform/tools/tradefederation/+/android16-release/src/com/android/tradefed/targetprep/RunCommandTargetPreparer.java)\n\n - **short name:** run-command\n - **function:** executes arbitrary shell commands before or after test module execution\n - **options:**\n - **run-command:**adb shell command to run. May be repeated\n - **teardown-command:**adb shell command to run during teardown phase. May be repeated\n\nTest class\n----------\n\nA test class is the Trade Federation class to use to execute the test. \n\n \u003ctest class=\"com.android.tradefed.testtype.AndroidJUnitTest\"\u003e\n \u003coption name=\"package\" value=\"android.test.example.helloworld\"/\u003e\n \u003coption name=\"runner\" value=\"android.support.test.runner.AndroidJUnitRunner\"/\u003e\n \u003c/test\u003e\n\nHere are three common test classes:\n\n- class name: [GTest](https://android.googlesource.com/platform/tools/tradefederation/+/android16-release/test_framework/com/android/tradefed/testtype/GTest.java)\n\n - **short name:** gtest\n - **function:** A Test that runs a native test package on given device.\n - **options:**\n - **native-test-device-path:**The path on the device where native tests are located.\n- class name: [InstrumentationTest](https://android.googlesource.com/platform/tools/tradefederation/+/android16-release/test_framework/com/android/tradefed/testtype/InstrumentationTest.java)\n\n - **short name:** instrumentation\n - **function:** A Test that runs an instrumentation test package on given device\n - **options:**\n - **package:**The manifest package name of the Android test application to run.\n - **class:**The test class name to run.\n - **method:**The test method name to run.\n- class name: [AndroidJUnitTest](https://android.googlesource.com/platform/tools/tradefederation/+/android16-release/test_framework/com/android/tradefed/testtype/AndroidJUnitTest.java)\n\n - **function:** A Test that runs an instrumentation test package on given device using the android.support.test.runner.AndroidJUnitRunner This is the main way to execute an instrumentation test."]]