一键式创建GTest TDD测试平台

适用于C++ GTest测试平台搭建。直接上python脚本。

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import argparse
import os
import platform
import subprocess
from xml.etree import ElementTree as ET


default_root_path = "d:\\test\\UTtest"


class DeveloperTestTool:
    '''
    usage:
    windows:
        python create_ohos_dev_self_test_exec_env.py -w d:\\test # 指定路径配置
        or
        python3 create_ohos_dev_self_test_exec_env.py # 默认路径配置.
    linux:
        python3 create_ohos_dev_self_test_exec_env.py -w /home # 指定路径配置
        note: no default path in linux
    '''
    def __init__(self, root_path):
        self.current_os = platform.system()
        if self.current_os == "Windows":
            self.root_path = default_root_path if len(root_path.strip()) == 0 else root_path
        elif self.current_os == "Linux":
            self.root_path = root_path

        self.testcase_path = os.path.join(self.root_path, "testcase", "tests")

    @staticmethod
    def git_clone(remote_url, local_path):
        subprocess.run(["git", "clone", remote_url, local_path])

    def config_developer_test(self):
        download_path = os.path.join(self.root_path, "developer_test")
        remote_url = "https://gitee.com/openharmony/testfwk_developer_test.git"
        DeveloperTestTool.git_clone(remote_url, download_path)

    def config_xdevice(self):
        download_path = os.path.join(self.root_path, "xdevice")
        remote_url = "https://gitee.com/openharmony/testfwk_xdevice.git"
        DeveloperTestTool.git_clone(remote_url, download_path)

    def update_user_config_xml(self):
        if self.current_os == "Windows":
            config_xml_path = self.root_path + "\\developer_test\\config\\user_config.xml"
        elif self.current_os == "Linux":
            config_xml_path = os.path.join(self.root_path, "developer_test", "config", "user_config.xml")
        else:
            print("This is neither Windows nor Linux.")
            return

        tree = ET.parse(config_xml_path)
        root = tree.getroot()
        node = root.find("test_cases").find("dir")
        node.text = self.testcase_path
        tree.write(config_xml_path, encoding="utf-8", xml_declaration=True)

    def done(self):
        self.config_developer_test()
        self.config_xdevice()
        self.update_user_config_xml()


def get_args():
    parser = argparse.ArgumentParser()
    parser.add_argument("--work_path", "-w", type=str, default=default_root_path, help="work path")
    args = parser.parse_args()
    return args


def main():
    args = get_args()
    test_tool = DeveloperTestTool(args.work_path)
    if not os.path.exists(test_tool.root_path):
        os.makedirs(test_tool.root_path)

    if not os.path.exists(test_tool.testcase_path):
        os.makedirs(test_tool.testcase_path)

    test_tool.done()


if __name__ == "__main__":
    main()

目录层级:

.
├── developer_test
├── testcase
└── xdevice

developer_test\config\user_config.xml文件中测试用例路径已经更新,请把测试用例目录直接放到该配置指向的路径下:
在这里插入图片描述
使用说明:

  • 指令格式请参见脚本
  • 可以修改默认安装路径(windows平台)。linux下是没有默认安装路径的。
  • 关于GTest怎么跑TDD,请参阅harmony 鸿蒙开发自测试执行框架使用指南。比如运行openharmony的form_fmk仓库(模块)FmsFormMgrServiceTest测试套测试用例FormMgrService_0128:run -t UT -tp form_fwk -ts FmsFormMgrServiceTest -tc FmsFormMgrServiceTest.FormMgrService_0128

相关推荐

  1. 【Docker】离线安装docker、docker-compose

    2024-07-10 01:24:05       68 阅读
  2. 台PC创建多个Git平台账号

    2024-07-10 01:24:05       53 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-10 01:24:05       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-10 01:24:05       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-10 01:24:05       45 阅读
  4. Python语言-面向对象

    2024-07-10 01:24:05       55 阅读

热门阅读

  1. Pytest单元测试系列[v1.0.0][高级技巧]

    2024-07-10 01:24:05       17 阅读
  2. CLIP-EBC:通过增强的逐块分类,CLIP能够准确计数

    2024-07-10 01:24:05       21 阅读
  3. #pragma 指令

    2024-07-10 01:24:05       23 阅读
  4. C++休眠的方法

    2024-07-10 01:24:05       23 阅读
  5. Spring容器加载Bean和JVM加载类

    2024-07-10 01:24:05       20 阅读
  6. word 使用手册

    2024-07-10 01:24:05       27 阅读
  7. winform4

    winform4

    2024-07-10 01:24:05      22 阅读
  8. PlugLink:小微企业自动化运营的魔法盒子

    2024-07-10 01:24:05       27 阅读
  9. Centos7删除MariaDB

    2024-07-10 01:24:05       22 阅读