一键式创建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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值