Skip to main content

UTest 自动化测试框架核心包(core 模块)

Project description

UTest 自动化测试框架 - 快速上手

本框架基于 ubox-py-sdk,提供简洁的测试用例编写与执行能力:步骤与断言、截图、录制、logcat 采集、性能采集与报告导出等。

1. 环境与安装

  • Python 3.9+(推荐按 run.sh 中方式创建虚拟环境)
  • 依赖通过 requirements.txt 安装

安装依赖(清华源示例):

uv pip install -U -r requirements.txt --index-url https://pypi.tuna.tsinghua.edu.cn/simple

2. 基础配置(config.yml)

关键项:

  • task.serial_num:设备序列号
  • task.os_type:android | ios | hm
  • task.app_name:被测应用包名或安装包
  • test.selected_tests:要执行的用例名称(为空执行全部)

3. 运行测试

  • 更改配置文件后直接运行(读取 config.yml):
uv run start_test.py

执行后输出目录:

  • test_result/log/<用例名>/:用例日志(perf.json、logcat.txt 等)
  • test_result/case/<用例名>/pic/:截图
  • Excel 报告:在 test_result/log 根目录生成

4. 如何编写用例

参考:

  • 真实业务:test_cases/user_tests_0.py(腾讯视频小游戏)
  • Demo:test_cases/user_tests_1.py(框架能力演示)

示例骨架:

from core.test_case import TestCase, StepStatus, FailureStrategy
from ubox_py_sdk import Device

class MyTest(TestCase):
    def __init__(self, device: Device):
        super().__init__(name="我的用例", description="用例描述", device=device)
        self.failure_strategy = FailureStrategy.STOP_ON_FAILURE

    def setup(self):
        # (可选)启动被测应用
        pkg = self.get_package_name()
        if pkg:
            self.start_step("启动应用", f"启动: {pkg}")
            ok = self.device.start_app(pkg)
            self.assert_true("应用应成功启动", ok)
            self.end_step(StepStatus.PASSED if ok else StepStatus.FAILED)
        # 录制(路径自动记录到结果)
        self.start_record()
        # logcat(仅记录文件路径,不需要手动停止)
        self.start_logcat()

    def run_test(self):
        # 步骤与断言
        self.start_step("准备场景", "示例")
        self.assert_true("环境应就绪", True)
        self.end_step(StepStatus.PASSED)

        # 关键阶段开启性能采集
        self.start_step("开启性能采集", "开始perf")
        started = self.start_perf()
        self.assert_true("性能采集应成功启动", started)
        self.end_step(StepStatus.PASSED if started else StepStatus.FAILED)

        # 业务操作...
        # ...
        # 停止性能采集:停止后自动解析 get_log_dir()/perf.json
        self.stop_perf()

    def teardown(self):
        # 停止录制
        self.stop_record()
        # (可选)关闭应用并回到桌面
        pkg = self.get_package_name()
        if pkg:
            self.device.stop_app(pkg)
        self.device.press("HOME")

要点与要求:

  • 用例名称/描述:在 init 的 name、description 设置。
  • 步骤管理:start_step/end_step;在步骤内断言失败会自动标记结果,end_step 不是必须显式调用,但建议在成功路径显式结束以便报告更清晰。
  • 断言:assert_true、assert_equal、assert_contains 等;失败按策略决定是否中断。
  • 截图:失败/通过(可配置)时自动截图,也可随时 take_screenshot("name")。
  • 录制:start_record()/stop_record();只记录文件路径,报告展示。
  • logcat:start_logcat();记录输出文件路径(logcat.txt),报告展示。
  • 性能:start_perf()/stop_perf();设备端在停止时写入 get_log_dir()/perf.json,框架自动解析并汇总 FPS/Jank/CPU/GPU/温度/功耗/内存/网络等指标到报告。

5. 报告

  • 自动生成 Excel 报告,包含:
    • 用例信息与状态
    • 步骤详情与截图
    • 录制与 logcat 文件路径
    • 性能监控关键指标(从 perf.json 解析的汇总)

6. 建议

  • 步骤小而清晰、断言贴近业务、仅在关键路径采集性能、出错即截图便于复盘。

编译

uv build

发布包

uv publish --publish-url https://mirrors.tencent.com/repository/pypi/tencent_pypi/simple

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

utest_auto_core-0.1.3.tar.gz (201.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

utest_auto_core-0.1.3-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

Details for the file utest_auto_core-0.1.3.tar.gz.

File metadata

  • Download URL: utest_auto_core-0.1.3.tar.gz
  • Upload date:
  • Size: 201.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.3

File hashes

Hashes for utest_auto_core-0.1.3.tar.gz
Algorithm Hash digest
SHA256 74416a025700e694b2613ab6c424501ff3b947e11a4efa1d3bd00463734e66f8
MD5 7ed8eb55a583e0e626234d7a03ba153d
BLAKE2b-256 9a167e91921551d618dc12d0f86bf121ed77604cc3613960a1fa18ae86b62b16

See more details on using hashes here.

File details

Details for the file utest_auto_core-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for utest_auto_core-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 dbe83647df27e306f5a2629174a712ea279dcffbf356562fedc5f0d1937ae47d
MD5 c3b2bf4523255648ba1c3d6afb392d05
BLAKE2b-256 2b518e634ca24d9c512cf589ff3f246f4ed891dc8b7136776b0db82b7030d5c1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page