minium 框架

框架优点
框架缺点
技术选型

minium 框架介绍

Properties

名称类型默认值说明

环境搭建

搭建 Minium Doc(微信官方人员确认,无需进行本地搭建,本地搭建的都是错的,而且还是旧的文档)

无需构建,直接访问官方文档(https://minitest.weixin.qq.com/#/

安装软件
安装 minium
特别说明
配置微信开发者工具
"path/to/cli" auto --project "path/to/project" --auto-port 9420

路径说明

"C:/Program Files (x86)/Tencent/微信web开发者工具/cli" auto --project "C:/WeChatProjects/miniprogram-1" --auto-port 9420

配置信息

代码结构目录

模拟器 Config.json
{
    "project_path": "C:\\WeChatProjects\\miniprogram-1",
    "dev_tool_path": "C:\\Program Files (x86)\\Tencent\\微信web开发者工具\\cli.bat",
    "debug_mode": "debug",
    "test_port": 9420,
    "platform": "ide",
    "app": "wx",
    "assert_capture": true,
    "request_timeout":60,
    "remote_connect_timeout": 300,
    "auto_relaunch": true
}

真机 Config.json
{
    "project_path": "C:\\WeChatProjects\\xxx_chinamobile-pmc_migration2\\unpackage\\dist\\build\\mp-weixin",
    "dev_tool_path": "C:\\Program Files (x86)\\Tencent\\微信web开发者工具\\cli.bat",
    "debug_mode": "debug",
    "test_port": 9420,
    "platform": "Android",
    "app": "wx",
    "enable_app_log": true,
    "device_desire": {
        "serial": "d310bf55"
    },
    "assert_capture": true,
    "request_timeout":60,
    "remote_connect_timeout": 300,
    "auto_relaunch": true
}

Suite.json
{
    "pkg_list": [
      {
        "case_list": [
          "test_*"
        ],
        "pkg": "testcase.*_test"
      }
    ]
  }

测试用例

first_test.py
# !/usr/bin/python
# -*- coding: utf-8 -*-

"""
@File    : first_test.py
@Create Time: 2022-06-01 16:17
@Description:
"""


import minium


class FirstTest(minium.MiniTest):
    def test_get_system_info(self):
        sys_info = self.mini.get_system_info()
        print("FirstTest: ", sys_info)
        self.assertIn("SDKVersion", sys_info)

if __name__ == "__main__":
    import unittest
    loaded_suite = unittest.TestLoader().loadTestsFromTestCase(FirstTest)
    result = unittest.TextTestRunner().run(loaded_suite)
    print(result)


主程序入口

run.py
# !/usr/bin/python
# -*- coding: utf-8 -*-

"""
@File    : run.py
@Create Time: 2022-06-01 17:21
@Description:
"""

import os

# 运行执行class文件中的指定用例
cmd0 = "minitest -m testcase.first_test --case test_get_system_info -c config.json -g"
# 运行执行testcase文件中的指定用例
cmd1 = "minitest -m testcase.first_test -c config.json -g"
# 按照suite配置执行用例
cmd2 = "minitest -s suite.json -c config.json -g"

os.system(cmd0)

执行用例

测试报告

测试结果存储在 outputs 下,运行命令

python -m http.server 12345 -d outputs

然后在浏览器上访问 http://localhost:12345 即可查看报告

参考资料

https://blog.csdn.net/jiangjunsss/article/details/120228371
https://blog.csdn.net/baguenaudier/article/details/124478687
https://blog.csdn.net/weixin_49546967/article/details/119858529
https://minitest.weixin.qq.com/#/minium/Python/readme
https://developers.weixin.qq.com/community/develop/article/doc/0000cae3a58748ed7f2c8975351413


↙↙↙阅读原文可查看相关链接,并与作者交流