일부 테스트 모듈은 맞춤 설정이 필요할 수 있고 테스트 사례 자체에서 실행될 수 없는 단계를 삭제해야 할 수 있습니다. 일반적인 예는 다음과 같습니다.
다른 APK 설치하기(테스트 APK 외)
기기에 일부 파일 푸시하기
명령어(예: adb shell pm ...) 실행하기
이전에는 일반적으로 구성요소팀에서 이러한 작업을 실행하기 위해 호스트 측 테스트를 작성했으며, 테스트를 실행하기 위해 Trade Federation 하네스에 대한 이해가 필요하고 테스트 모듈의 복잡도가 증가했습니다.
이러한 작업을 지원하기 위해 CTS에서 차용한 테스트 모듈 구성이라는 개념을 도입했으며 단 몇 줄의 구성으로 위의 공통 작업 목록을 실행할 수 있습니다. 유연성을 최대화하려면 ITargetPreparer 또는 ITargetCleaner에서 정의한 자체 타겟 준비자를 구현하고 자체 테스트 모듈 구성에서 사용하도록 구성할 수도 있습니다.
테스트 모듈의 테스트 모듈 구성은 'AndroidTest.xml'이라는 필수 XML 파일로 최상위 모듈 소스 폴더에 추가됩니다. XML은 Trade Federation 테스트 자동화 하네스에서 사용하는 구성 파일 형식을 따릅니다.
현재 테스트 모듈 구성을 통해 처리되는 기본 태그는 'target_preparer' 및 'test' 태그입니다.
타겟 준비자
'target_preparer' 태그는 이름에서 알 수 있듯이 설정 메서드를 제공하는 타겟 준비자(ITargetPreparer 참고)를 정의하며, 이 타겟 준비자는 테스트를 위해 테스트 모듈이 실행되기 전에 호출됩니다. 또한 'target_preparer' 태그에서 참조되는 클래스가 ITargetCleaner도 구현하는 경우, 테스트 모듈이 완료된 후에 ITargetCleaner의 teardown 메서드가 호출됩니다.
기본 일반 모듈 구성을 사용하려면 테스트 모듈의 최상위 폴더에 'AndroidTest.xml'이라는 새 파일을 추가하고 다음 콘텐츠를 채웁니다.
테스트 모듈이 호출되기 전에 기기에서 셸 명령어 'settings put secure accessibility_enabled 1'을 실행합니다.
테스트 모듈이 완료된 후 셸 명령어 'settings put secure accessibility_enabled 0'을 실행합니다.
이 특정 예에서 접근성은 테스트 모듈 실행 전후에 각각 사용 설정 또는 사용 중지됩니다. 간단한 예 하나만 살펴보았기 때문에, 이제 'option' 태그가 사용되는 방식에 관해 더 자세히 알아볼 필요가 있습니다. 위에 표시된 것처럼 태그는 name과 value라는 두 가지 속성을 가질 수 있습니다. name 속성은 준비자가 제공하는 옵션 중 하나를 참조해야 합니다.
value 필드의 정확한 목적은 준비자가 옵션을 정의한 방식에 따라 다릅니다. 문자열, 숫자, 불리언 또는 파일 경로일 수 있습니다.
다음은 3가지 일반적인 타겟 준비자에 관한 요약입니다.
이 준비자는 폴더에서 폴더로 또는 파일에서 파일로 푸시할 수 있습니다. 즉, 파일을 기기의 폴더 아래로 푸시할 수 없습니다. 또한, 폴더 아래에 있는 대상 파일 이름도 지정해야 합니다.
옵션:
push-file: push-spec으로 로컬 파일이 푸시되어야 하는 기기 경로를 지정합니다. 반복될 수 있습니다. 여러 파일이 동일한 원격 경로로 푸시되도록 구성된 경우 최근에 지정된 파일이 푸시됩니다.
push:(지원 중단됨) '/path/to/srcfile.txt->/path/to/destfile.txt' 또는 '/path/to/srcfile.txt->/path/to/destdir/'로 형식이 지정된 push-spec으로, 반복될 수 있습니다. 이 경로는 테스트 모듈 디렉터리 또는 외부 디렉터리 자체에 대한 상대 경로일 수 있습니다.
post-push: 모든 푸시를 시도한 후 기기에서 실행하는 명령어('adb shell
<your command>' 사용)입니다. 일반적인 사용 사례는 권한에 chmod를 사용하는 것입니다.
기능: android.support.test.runner.AndroidJUnitRunner를 사용하여 주어진 기기에서 계측 테스트 패키지를 실행하는 테스트입니다. 이는 계측 테스트를 실행하는 주된 방법입니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","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-07-27(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."]]