| <html devsite><head> |
| |
| <meta name="book_path" value="/_book.yaml"/> |
| |
| <meta name="project_path" value="/_project.yaml"/> |
| </head> |
| <body> |
| |
| <!-- |
| Copyright 2018 The Android Open Source Project |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| |
| <h1 id="android_platform_testing" class="page-title">Android 平台测试</h1> |
| |
| <p>本内容面向 Android 平台开发者。在了解如何在 Android 平台上进行测试之前,请参阅 <a href="/devices/architecture">Android 平台架构</a>,大致了解相关的信息。</p> |
| |
| <h2 id="whats_new">新变化</h2> |
| |
| <h3 id="test_development_workflow">测试开发工作流</h3> |
| |
| <p><a href="/compatibility/tests/development">测试开发工作流</a>小节现在包含介绍性材料,其中包括所有主要测试类型的端到端示例。</p> |
| |
| <h3 id="simple_test_configuration">简单的测试配置</h3> |
| |
| <p><a href="https://android.googlesource.com/platform/build/soong/">Soong 编译系统</a>在 Android 8.0 (Oreo) 中引入,在 Android Q 中实现了对 <code>android_test</code> 的支持,现在可在 Android 开源项目 (AOSP) master 分支中找到它。Soong 基于 Blueprint 的配置比以前的 Make 解决方案简单得多。</p> |
| |
| <h3 id="atest">Atest</h3> |
| |
| <p><a href="/compatibility/tests/development/atest">Atest</a> 是一个命令行工具,用户可以使用该工具在本地编译、安装并运行 Android 测试。建议采用此标准对您的功能进行初始测试。</p> |
| |
| <h2 id="what_and_how_to_test">测试什么以及如何测试</h2> |
| |
| <p>平台测试通常与一个或多个 Android 系统服务或硬件抽象层 (HAL) 交互、执行受测对象的功能,并断言测试结果的正确性。</p> |
| |
| <p>因此,平台测试可以:</p> |
| |
| <ol> |
| <li>通过应用框架执行框架 API;执行的特定 API 可能包括:<ul> |
| <li>用于第三方应用的公共 API</li> |
| <li>用于特权应用的隐藏 API,也称为系统 API</li> |
| <li>私有 API(@hide 或受保护,软件包私有)</li> |
| </ul></li> |
| <li>直接通过原始 binder/IPC 代理调用 Android 系统服务</li> |
| <li>通过低级别 API 或 IPC 接口直接与 HAL 交互</li> |
| </ol> |
| |
| <p>类型 1 和 2 通常编写为<a href="/compatibility/tests/development/instrumentation">插桩测试</a>,而类型 3 通常使用 <a href="https://github.com/google/googletest" class="external">gtest</a> 框架编写为<a href="/compatibility/tests/development/native">原生测试</a>。</p> |
| |
| <p>如需了解详情,请参阅我们的端到端示例:</p> |
| |
| <ul> |
| <li><a href="/compatibility/tests/development/instr-app-e2e.md">针对应用的插桩</a></li> |
| <li><a href="/compatibility/tests/development/instr-self-e2e.md">自插桩测试</a></li> |
| <li><a href="/compatibility/tests/development/native-func-e2e.md">原生测试</a></li> |
| </ul> |
| |
| <p>请熟悉以下工具,因为它们是在 Android 系统中进行测试所固有的工具。</p> |
| |
| <h2 id="compatibility_test_suite_cts">兼容性测试套件 (CTS)</h2> |
| |
| <p><a href="/compatibility/cts/">Android 兼容性测试套件</a>是一个包含各种类型的测试的套件,用于确保 Android 框架实现在 OEM 合作伙伴以及平台版本之间保持兼容性。<strong>该套件还包括插桩测试和原生测试(也使用 gtest 框架)。</strong></p> |
| |
| <p>CTS 与平台测试并不互斥,下面是一些常规准则:</p> |
| |
| <ul> |
| <li>如果测试断言框架 API 函数/行为的正确性,并且应该在 OEM 合作伙伴之间强制执行,那么它应该在 CTS 中</li> |
| <li>如果测试的意图是在平台开发周期内捕捉回归,并且可能需要特许权限来执行,还可能依赖于实现细节(如 AOSP 中所发布),那么它只能是平台测试</li> |
| </ul> |
| |
| <h2 id="vendor_test_suite_vts">供应商测试套件 (VTS)</h2> |
| |
| <p><a href="/compatibility/vts/">供应商测试套件</a> (VTS) 会自动执行 HAL 和操作系统内核测试。要使用 VTS 测试 Android 原生系统实现,请设置一个测试环境,然后使用 VTS 方案来测试相应补丁程序。</p> |
| |
| <h2 id="trade_federation_testing_infrastructure">Trade Federation 测试基础架构</h2> |
| |
| <p><a href="/devices/tech/test_infra/tradefed/">Trade Federation</a>(简称 tradefed 或 TF)是一种连续的测试框架,专门用于在 Android 设备上运行测试。TF 可以在本地、在桌面设备上以及在平台检验处运行功能测试。要在 TF 中运行测试,您必须具备两个文件,一个是 Java 测试源文件,另一个是 XML 配置文件。有关示例,请参阅 <a href="https://android.googlesource.com/platform/tools/tradefederation/contrib/+/master/src/com/android/example/RebootTest.java" class="external">RebootTest.java</a> 和 <a href="https://android.googlesource.com/platform/tools/tradefederation/contrib/+/master/res/config/example/reboot.xml" class="external">reboot.xml</a>。</p> |
| |
| <h2 id="debugging">调试</h2> |
| |
| <p><a href="/devices/tech/debug/">调试</a>部分总结了开发平台级功能时,可用于调试、跟踪和分析原生 Android 平台代码的实用工具和相关命令。</p> |
| |
| </body></html> |