# 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**: 4 - **Created**: 2026-03-17 - **Last Updated**: 2026-03-30 ## 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 工具连接到开发环境 ## 项目结构 ``` 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 │ │ │ │ │ ├── arraybufferconversions/ # ArrayBuffer 转换测试 │ │ │ └── ArrayBufferContextsTest.test.ets │ │ │ │ │ ├── booleanconversions/ # Boolean 转换测试 │ │ │ ├── BooleanContextsTest1.test.ets │ │ │ └── BooleanContextsTest2.test.ets │ │ │ │ │ ├── consoleconversions/ # Console 转换测试 │ │ │ ├── ConsoleContextsTest1.test.ets │ │ │ ├── ConsoleContextsTest2.test.ets │ │ │ ├── ConsoleContextsTest3_1.test.ets │ │ │ ├── ConsoleContextsTest3_2.test.ets │ │ │ ├── ConsoleContextsTest4.test.ets │ │ │ ├── ConsoleContextsTest5.test.ets │ │ │ └── ConsoleContextsTest6.test.ets │ │ │ │ │ ├── formatterconversions/ # Formatter 转换测试 │ │ │ └── FormatterContextsTest.test.ets │ │ │ │ │ ├── iteratorresultconversions/ # IteratorResult 转换测试 │ │ │ └── IteratorResultContextsTest.test.ets │ │ │ │ │ ├── nullconversions/ # Null 转换测试 │ │ │ └── NullContextsTest.test.ets │ │ │ │ │ ├── reflectconversions/ # Reflect 转换测试 │ │ │ └── ReflectContextsTest.test.ets │ │ │ │ │ ├── stackTraceconversions/ # StackTrace 转换测试 │ │ │ └── StackTraceContextsTest.test.ets │ │ │ │ │ └── weakrefconversions/ # WeakRef 转换测试 │ │ └── WeakRefContextsTest.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` - **测试包名**: `XTS_DEMO.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 ``` ### 测试说明 #### 测试套件: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` ## 测试开发指南 ### 添加新测试 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=WeakRefContextsTest OHOS_REPORT_STATUS: suiteconsuming=475 OHOS_REPORT_RESULT: stream=Tests run: 1114, Failure: 0, Error: 0, Pass: 1114, Ignore: 0 OHOS_REPORT_CODE: 0 OHOS_REPORT_STATUS: taskconsuming=50709 TestFinished-ResultCode: 0 TestFinished-ResultMsg: your test finished!!! user test finished. ``` **文档版本**: 1.0 **最后更新**: 2026年3月28日