适用于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()
pass
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下是没有默认安装路径的。