HarmonyOS鸿蒙Next中UI单元测试驱动序列化失败

HarmonyOS鸿蒙Next中UI单元测试驱动序列化失败 04-01 11:39:29.297   11598-11598   C03100/UiTestKit_Client         cn.com.wi…tProject  I     [uitest_napi.cpp:(Export)] Begin export uitest apis 04-01 11:39:29.309   11598-11598   C03100/UiTestKit_Client         cn.com.wi…tProject  I     [uitest_napi.cpp:(Export)] End export uitest apis 04-01 11:39:29.311   11598-11598   A03d00/JSAPP                    cn.com.wi…tProject  W     UiTestKit_exporter: systemParameter “persist.ace.testmode.enabled” is not set! 04-01 11:39:29.316   11598-11598   A03d00/JSAPP                    cn.com.wi…tProject  W     UiTestKit_exporter: Cannot get AbilityDelegator, uitest_daemon need to be pre-started 04-01 11:39:29.318   11598-11836   C03100/UiTestKit_Conn           cn.com.wi…tProject  I     [ipc_transactor.cpp:(InitAndConnectPeer)] Begin 04-01 11:39:29.709   11598-11598   C03100/UiTestKit_Client         cn.com.wi…tProject  I     [uitest_napi.cpp:(WaitForConnectionIfNeed)] Begin WaitForConnection 04-01 11:39:34.324   11598-11836   C03100/UiTestKit_Conn           cn.com.wi…tProject  E     [ipc_transactor.cpp:(WaitForPublishedCaller)] Wait for ApiCaller publish by server timeout 04-01 11:39:34.324   11598-11836   C03100/UiTestKit_Conn           cn.com.wi…tProject  E     [ipc_transactor.cpp:(InitAndConnectPeer)] Failed to get apiCaller object from peer 04-01 11:39:34.324   11598-11836   C03100/UiTestKit_Client         cn.com.wi…tProject  I     [uitest_napi.cpp:(operator())] End setup transaction connection, result=0 04-01 11:39:34.325   11598-11598   C03100/UiTestKit_Client         cn.com.wi…tProject  I     [uitest_napi.cpp:(UnmarshalReply)] Start to Unmarshal transaction result 04-01 11:39:34.325   11598-11598   C03100/UiTestKit_Client         cn.com.wi…tProject  E     [uitest_napi.cpp:(UnmarshalReply)] ErrorInfo: code=‘17000006’, message=‘ipc connection is dead’ 04-01 11:39:34.325   11598-11598   C03100/UiTestKit_Client         cn.com.wi…tProject  I     [uitest_napi.cpp:(UnmarshalReply)] Start to Unmarshal return value: null 使用了自定义的UIAbility和TestRunner就会有问题


更多关于HarmonyOS鸿蒙Next中UI单元测试驱动序列化失败的实战教程也可以访问 https://www.itying.com/category-93-b0.html

6 回复

连接设备,执行“hdc shell param set persist.ace.testmode.enabled 1”命令是否success。

执行“hdc shell pidof uitest”命令,查看是否存在被占用的线程。

执行“hdc shell uitest start-daemon singleness”命令,检查是否有信息打印。

更多关于HarmonyOS鸿蒙Next中UI单元测试驱动序列化失败的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


$ param set persist.ace.testmode.enabled 1
Set parameter persist.ace.testmode.enabled 1 success
$ pidof uitest
$ uitest start-daemon singleness
$ 

并不能解决,我看下写个测试项目代码上传把

尊敬的开发者,您好,
为了尽快解决您的问题,需要您进一步提供如下信息:
根据您提供的日志未能复现您的场景,麻烦您提供下最小可复现的demo,方便定位问题。

在HarmonyOS Next中,UI单元测试驱动序列化失败通常是由于测试框架与UI组件状态序列化不兼容导致。需检查测试用例是否使用了不支持的UI组件或状态管理方式。确保测试环境配置正确,并更新测试框架至最新版本。

根据您提供的日志,UI单元测试驱动序列化失败的核心原因是 uitest_daemon 服务未启动,导致IPC连接超时和死亡。具体分析如下:

1. 根本原因分析: 日志中关键错误信息有两处:

  • UiTestKit_exporter: Cannot get AbilityDelegator, uitest_daemon need to be pre-started:这明确指出测试框架无法获取AbilityDelegator,因为 uitest_daemon 服务没有被预先启动。这是HarmonyOS Next UI测试框架(UiTestKit)运行所依赖的核心后台服务。
  • Wait for ApiCaller publish by server timeoutErrorInfo: code='17000006', message='ipc connection is dead':由于 uitest_daemon 未运行,测试客户端(您的测试代码)无法与服务端建立有效的IPC(进程间通信)连接,最终导致连接超时并中断,序列化过程因此失败。

2. 解决方案: 问题在于测试环境未正确初始化。您需要确保在运行UI测试(特别是使用了自定义UIAbility和TestRunner时)之前,显式启动 uitest_daemon 服务。

操作步骤: 在设备或模拟器的 命令行(hdc shell) 中,执行以下命令来启动服务:

hilog -r & uitest_daemon &

或者,更直接地启动守护进程:

start uitest_daemon

执行后,再重新运行您的UI单元测试。

3. 补充说明:

  • persist.ace.testmode.enabled 参数未设置的警告通常不会直接导致此序列化失败,核心仍是守护进程未运行。
  • 当使用自定义的 UIAbilityTestRunner 时,测试框架对进程生命周期和IPC连接的依赖更强,因此 uitest_daemon 未运行的影响会立即显现。

请先尝试启动 uitest_daemon 服务,这应该能解决您遇到的序列化失败问题。

回到顶部