# 0421 **Repository Path**: nanmubi/0421 ## Basic Information - **Project Name**: 0421 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-04-24 - **Last Updated**: 2026-04-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # HarmonyOS XTS 4.21 测试项目使用手册 ## 项目概述 本项目是 4.14 下发的 合并转换部分。 ## 环境要求 ### 开发环境 - **IDE**: DevEco Studio - **SDK**: OpenHarmony SDK 24 - **操作系统**: Windows 10/11 ### 测试设备 - RK3568 设备 + Dayu 3.24 img ## 项目结构 ``` entry/ ├── build/ # 构建输出目录 │ └── default/ │ └── outputs/default/ # 编译产物 │ ├── entry-default-signed.hap │ └── entry-default-unsigned.hap │ ├── src/ │ ├── hypium/ # Hypium 测试框架(不可修改) │ │ └── module/ # 测试框架核心模块 │ │ ├── assert/ # 断言方法库 │ │ ├── config/ # 配置服务 │ │ ├── kit/ # 系统测试工具包 │ │ ├── mock/ # Mock 工具 │ │ ├── report/ # 报告服务 │ │ ├── service/ # 核心服务层 │ │ └── types/ # 类型定义 │ │ │ ├── main/ # 主模块 │ │ ├── ets/ # 应用入口和页面 │ │ │ ├── entryability/ │ │ │ │ └── EntryAbility.ets │ │ │ └── pages/ │ │ │ └── Index.ets │ │ │ │ │ ├── resources/ # 资源文件 │ │ │ ├── base/ # 基础资源 │ │ │ │ ├── element/ # 元素资源(颜色/字符串等) │ │ │ │ ├── media/ # 媒体资源(图片等) │ │ │ │ └── profile/ # 配置文件 │ │ │ └── dark/ # 深色主题资源 │ │ │ │ │ └── src/ # ⭐ 重点:测试源码目录 │ │ └── test/ # 所有测试用例 │ │ ├── List.test.ets # 测试用例注册清单 │ │ │ │ │ ├── abcFileconversions/ # ABC 文件转换测试 │ │ │ └── AbcFileContextsTest.test.ets │ │ │ └── testrunner/ # 测试运行器 │ └── OpenHarmonyTestRunner.ets │ ├── src/test/ # 旧版测试目录(已废弃) │ ├── List.test.ets │ └── List.test.test.ets │ ├── .gitignore ├── build-profile.json5 # 构建配置 ├── hvigorfile.ts # 构建任务配置 ├── obfuscation-rules.txt # 代码混淆规则 └── oh-package.json5 # 依赖配置 ``` ## 应用信息 - **Bundle Name**: `com.example.helloworld` - **Module Name**: `entry` - **测试包名**: `entry-default-signed.hap` ## 测试执行 ### 前置条件 1. 确保 OpenHarmony 设备已连接到电脑 2. 使用 `hdc list targets` 确认设备连接状态 3. 确保 HAP 包已成功构建 ### 测试执行命令 #### 1. 安装测试包 ```bash # 安装已签名的 HAP 包 hdc install entry/build/default/outputs/default/entry-default-signed.hap ``` #### 2. 运行所有测试 ```bash # 运行功能测试 hdc shell aa test -b com.example.helloworld -m entry -s unittest /ets/testrunner/OpenHarmonyTestRunner -s timeout 15000 ``` ## 常见问题 ### Q1: hdc 命令不识别 **解决方案**: 1. 确保 OpenHarmony SDK 已正确安装 2. 将 SDK 的 toolchains 目录添加到系统 PATH 3. 在 DevEco Studio 中设置 SDK 路径:File > Settings > SDK > OpenHarmony SDK ### Q2: 设备连接失败 **解决方案**: 1. 检查设备是否已开启 USB 调试模式 2. 使用 `hdc list targets` 确认设备连接 3. 重启 hdc 服务:`hdc kill` 然后 `hdc start` ### Q3: 安装 HAP 失败 **解决方案**: 1. 检查 HAP 包是否存在 2. 确认设备有足够的存储空间 3. 卸载旧版本:`hdc shell bm uninstall -n com.example.helloworld` 4. 可以使用 手工 卸载 ### Q4: 构造签名失败 一般是第一次构造出现 ``` > hvigor ERROR: Failed :entry:default@SignHap... > hvigor ERROR: Failed to find the incremental input file: C:/Users/YT/.ohos/config/openharmony/default_test-project-0414_QyH6cwUa7pFragHWRbgUYdOVkcjEzyyZv1KeFbwabX0=.cer. > hvigor ERROR: BUILD FAILED in 7 s 215 ms ``` **解决方案**: 1. 文件 -> 项目结构 -> 签名配置 -> 自动签名 2. 文件 -> 使缓存失效 3. 构建 -> 清理项目 -> 重新构造 # 测试开发指南 ### 添加新测试 1. 在 `entry/src/main/src/test/` 目录下创建测试文件 2. 按照项目规范编写测试用例 3. 在 `List.test.ets` 中注册测试套件 ### 测试文件模板 ```typescript import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, TestType, Level, Size } from '../../../../hypium/index'; export default function YourTestSuite() { describe("YourTestSuite", (): void => { beforeAll(() => { // 在所有测试前执行 }); beforeEach(async () => { // 在每个测试前执行 }); afterEach(() => { // 在每个测试后执行 }); afterAll(() => { // 在所有测试后执行 }); /** * @tc.name testName001 * @tc.number SUB_SUBSYSTEM_MODULE_ACTION_0100 * @tc.desc Description of test functionality * @tc.type FUNCTION * @tc.size MEDIUMTEST * @tc.level LEVEL0 */ it("testName001", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, (): void => { // 测试代码 expect(actual).assertEqual(expected); }); }); } ``` ### 测试命名规范 - 测试文件: `[Component][N].test.ets`(如 `HashMap1.test.ets`) - 测试套件: `describe("ComponentTest", ...)` - 测试方法: `testComponent0001`, `testComponent0002`(顺序编号) - 测试编号: `SUB_[子系统]_[模块]_[方法/动作]_[序列号]` ## 代码规范 ### 文件头注释 所有测试文件必须包含 Apache 2.0 许可证头: ```typescript /* * Copyright (C) 2025-2026 Huawei Device Co., Ltd. * 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. */ ``` ### 断言语句 ```typescript // 值相等 expect(actual).assertEqual(expected); // 字符串比较(用于 undefined/null) expect(String(actual)).assertEqual('true'); expect(String(actual)).assertEqual('null'); // 对象深度相等 expect(obj1).assertEqual(obj2); ``` ## 快速开始 ### 第一次运行测试 ```bash # 2. 检查设备连接 hdc list targets # 3. 安装测试包 hdc install entry/build/default/outputs/default/entry-default-signed.hap # 4. 运行所有测试 hdc shell aa test -b com.example.helloworld -m entry -s unittest /ets/testrunner/OpenHarmonyTestRunner -s timeout 15000 ``` ``` OHOS_REPORT_STATUS: class=StaticAndInstanceFieldsTest OHOS_REPORT_STATUS: suiteconsuming=269 OHOS_REPORT_RESULT: stream=Tests run: 4, Failure: 0, Error: 0, Pass: 4, Ignore: 0 OHOS_REPORT_CODE: 0 OHOS_REPORT_STATUS: taskconsuming=269 TestFinished-ResultCode: 0 TestFinished-ResultMsg: your test finished!!! user test finished. ``` **文档版本**: 1.0 **最后更新**: 2026年4月20日