# test-project-0317 **Repository Path**: wayxingwork/test-project-0317 ## Basic Information - **Project Name**: test-project-0317 - **Description**: 测试项目0317 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-17 - **Last Updated**: 2026-03-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # HarmonyOS XTS 测试项目使用手册 ## 项目概述 本项目是 OpenHarmony XTS (XTS Compatibility Test Suite) 测试项目,用于测试 ArkTS API 和工具类功能。 ## 环境要求 ### 开发环境 - **IDE**: DevEco Studio - **SDK**: OpenHarmony SDK 24 - **操作系统**: Windows 10/11 ### 测试设备 - OpenHarmony 设备或模拟器 - 通过 hdc 工具连接到开发环境 ## 项目结构 ``` xts_demo_20260306/ ├── entry/ # 模块目录 │ ├── src/main/ │ │ ├── src/test/ # 测试文件目录 │ │ │ ├── contextsandconversions/ │ │ │ │ └── StringOperatorContextsTest.test.ets # 字符串操作上下文测试 │ │ │ └── List.test.ets # 测试套件列表 │ │ ├── testrunner/ # 测试运行器 │ │ │ └── OpenHarmonyTestRunner.ets │ │ ├── hypium/ # 测试框架(不可修改) │ │ └── module.json5 # 模块配置 │ └── build/ # 构建输出目录 │ └── default/outputs/default/ │ ├── entry-default-signed.hap # 已签名的 HAP 包 │ └── entry-default-unsigned.hap # 未签名的 HAP 包 ├── hvigor/ # 构建工具配置 │ └── hvigor-config.json5 ├── Test.json # 测试配置文件 ├── build-profile.json5 # 项目构建配置 ├── hvigorfile.ts # 构建脚本 └── oh-package.json5 # 依赖管理 ``` ## 应用信息 - **Bundle Name**: `com.example.helloworld` - **Module Name**: `entry` - **测试包名**: `XTS_DEMO.hap` ## 构建命令 ### 1. 构建 HAP 包 在 DevEco Studio 终端或命令行中执行: ```bash # 使用 hvigorw 构建(如果存在) hvigorw assembleHap --mode module -p product=default # 或者使用 DevEco Studio 的图形界面 # 点击菜单:Build > Build Hap(s) / APP(s) > Build Hap(s) ``` ### 2. 清理构建 ## 测试执行 ### 前置条件 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 ``` ### 测试说明 #### 测试套件:StringOperatorContextsTest 该测试套件包含 44 个测试用例,用于验证字符串操作在不同上下文中的行为。 **测试用例范围**: SUB_STRING_OPERATOR_CONTEXTS_0100 ~ SUB_STRING_OPERATOR_CONTEXTS_4400 **测试级别**: - LEVEL0: 基础功能测试 - LEVEL1: 重要功能测试 - LEVEL2: 一般功能测试 **测试类型**: - FUNCTION: 功能测试 - PERFORMANCE: 性能测试 - RELIABILITY: 可靠性测试 **测试大小**: - SMALLTEST: 小型测试(执行时间 < 30 秒) - MEDIUMTEST: 中型测试(执行时间 30-120 秒) - LARGETEST: 大型测试(执行时间 > 120 秒) ### 测试结果查看 #### 1. 命令行输出 测试执行后,hdc 会直接在命令行输出测试结果: ``` [INFO] Running tests... [INFO] Test Suite: StringOperatorContextsTest [INFO] [PASS] testStringOperatorContexts0001 [INFO] [PASS] testStringOperatorContexts0002 ... [INFO] Total: 44 tests [INFO] Passed: 44 [INFO] Failed: 0 ``` #### 2. 设备日志 查看设备日志获取详细信息: ```bash # 查看测试日志 hdc shell hilog | grep "StringOperatorContextsTest" # 或查看所有日志 hdc shell hilog ``` #### 3. 测试报告 测试报告保存在以下位置: ``` .hvigor/report/report-[时间戳].json ``` #### 4. DevEco Studio 查看 在 DevEco Studio 中: 1. 打开 Run 窗口(View > Tool Windows > Run) 2. 查看测试执行结果和详细信息 ## 常见问题 ### 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` ### Q4: 测试运行超时 **解决方案**: 1. 检查 Test.json 中的 timeout 配置 2. 调整 testcase-timeout 参数 3. 检查设备性能和网络连接 ### Q5: 构建失败 **解决方案**: 1. 运行 `hvigorw clean` 清理构建缓存 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 # 1. 构建 HAP 包 hvigorw assembleHap --mode module -p product=default # 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 # hdc shell aa test -b com.example.helloworld -m entry -s unittest /ets/testrunner/OpenHarmonyTestRunner -s timeout 15000 ``` ### 查看构建产物 ```bash # 查看 HAP 包 dir entry\build\default\outputs\default\*.hap # 查看构建日志 dir .hvigor\outputs\build-logs\ ``` ## 附录 ### 测试配置参数 | 参数 | 说明 | 默认值 | |------|------|--------| | test-timeout | 测试套件超时时间(毫秒) | 180000 | | shell-timeout | Shell 命令超时时间(毫秒) | 600000 | | testcase-timeout | 测试用例超时时间(毫秒) | 180000 | ### 支持的测试类型 - FUNCTION: 功能测试 - PERFORMANCE: 性能测试 - POWER: 功耗测试 - RELIABILITY: 可靠性测试 - SECURITY: 安全性测试 - GLOBAL: 全局测试 - COMPATIBILITY: 兼容性测试 - USER: 用户测试 - STANDARD: 标准测试 - SAFETY: 安全测试 - RESILIENCE: 恢复性测试 ### 支持的测试级别 - LEVEL0: 最高优先级测试 - LEVEL1: 高优先级测试 - LEVEL2: 中优先级测试 - LEVEL3: 低优先级测试 - LEVEL4: 最低优先级测试 ## 联系与支持 如遇到问题,请参考: 1. DevEco Studio 官方文档 2. OpenHarmony XTS 测试规范 3. 项目 AGENTS.md 文件 --- **文档版本**: 1.0 **最后更新**: 2026年3月10日