XMind2TestCase 工具,提供了一個高效測試用例設計的解決方案(開源)python
軟件測試過程當中,最重要、最核心就是測試用例的設計,也是測試童鞋、測試團隊平常投入最多時間的工做內容之一。git
然而,傳統的測試用例設計過程有不少痛點:github
基於這些狀況,如今愈來愈多公司選擇使用思惟導圖這種高效的生產力工具進行用例設計,特別是敏捷開發團隊。web
事實上也證實,思惟導圖其發散性思惟、圖形化思惟的特色,跟測試用例設計時所需的思惟很是吻合,因此在實際工做中極大提高了咱們測試用例設計的效率,也很是方便測試用例評審。json
可是與此同時,使用思惟導圖進行測試用例設計的過程當中也帶來很多問題:bash
綜合以上狀況,咱們能夠發現不一樣的測試用例設計方式,各有各個的優劣。ide
那麼問題來了,咱們能不能將它們各自優勢合在一塊兒呢?這樣不就能夠提高咱們的效率了!工具
因而,這時候 XMind2TestCase 就應運而生了,該工具基於 Python 實現,經過制定測試用例通用模板, 而後使用 XMind 這款廣爲流傳且開源的思惟導圖工具進行用例設計。 其中制定測試用例通用模板是一個很是核心的步驟(具體請看使用指南),有了通用的測試用例模板,咱們就能夠在 XMind 文件上解析並提取出測試用例所需的基本信息, 而後合成常見測試用例管理系統所需的用例導入文件。這樣就將 XMind 設計測試用例的便利與常見測試用例系統的高效管理結合起來了!測試
當前 XMind2TestCase 已實現從 XMind 文件到 TestLink 和 Zentao(禪道) 兩大常見用例管理系統的測試用例轉換,同時也提供 XMind 文件解析後的兩種數據接口 (TestSuites、TestCases兩種級別的JSON數據),方便快速與其餘測試用例管理系統打通。優化
pip3 install xmind2testcase
複製代碼
pip3 install -U xmind2testcase
複製代碼
Usage:
xmind2testcase [path_to_xmind_file] [-csv] [-xml] [-json]
Example:
xmind2testcase /path/to/testcase.xmind => output testcase.csv、testcase.xml、testcase.json
xmind2testcase /path/to/testcase.xmind -csv => output testcase.csv
xmind2testcase /path/to/testcase.xmind -xml => output testcase.xml
xmind2testcase /path/to/testcase.xmind -json => output testcase.json
複製代碼
Usage:
xmind2testcase [webtool] [port_num]
Example:
xmind2testcase webtool => launch the web testcase convertion tool locally -> 127.0.0.1:5001
xmind2testcase webtool 8000 => launch the web testcase convertion tool locally -> 127.0.0.1:8000
複製代碼
import json
import xmind
from xmind2testcase.zentao import xmind_to_zentao_csv_file
from xmind2testcase.testlink import xmind_to_testlink_xml_file
from xmind2testcase.utils import xmind_testcase_to_json_file
from xmind2testcase.utils import xmind_testsuite_to_json_file
from xmind2testcase.utils import get_xmind_testcase_list
from xmind2testcase.utils import get_xmind_testsuite_list
def main():
xmind_file = 'docs/xmind_testcase_template.xmind'
print('Start to convert XMind file: %s' % xmind_file)
zentao_csv_file = xmind_to_zentao_csv_file(xmind_file)
print('Convert XMind file to zentao csv file successfully: %s' % zentao_csv_file)
testlink_xml_file = xmind_to_testlink_xml_file(xmind_file)
print('Convert XMind file to testlink xml file successfully: %s' % testlink_xml_file)
testsuite_json_file = xmind_testsuite_to_json_file(xmind_file)
print('Convert XMind file to testsuite json file successfully: %s' % testsuite_json_file)
testcase_json_file = xmind_testcase_to_json_file(xmind_file)
print('Convert XMind file to testcase json file successfully: %s' % testcase_json_file)
testsuites = get_xmind_testsuite_list(xmind_file)
print('Convert XMind to testsuits dict data:\n%s' % json.dumps(testsuites, indent=2, separators=(',', ': '), ensure_ascii=False))
testcases = get_xmind_testcase_list(xmind_file)
print('Convert Xmind to testcases dict data:\n%s' % json.dumps(testcases, indent=4, separators=(',', ': ')))
workbook = xmind.load(xmind_file)
print('Convert XMind to Json data:\n%s' % json.dumps(workbook.getData(), indent=2, separators=(',', ': '), ensure_ascii=False))
print('Finished conversion, Congratulations!')
if __name__ == '__main__':
main()
複製代碼
from xmind2testcase.utils import get_xmind_testcase_list
xmind_file = 'docs/xmind_testcase_demo.xmind'
testcases = get_xmind_testcase_list(xmind_file)
print(testcases)
Output:
[
{ # 測試用例
"name": "測試用例1", # 用例標題
"version": 1, # 用例版本
"summary": "測試用例1", # 用例摘要
"preconditions": "前置條件", # 前置條件
"execution_type": 1, # 用例執行類型(1:手動、2:自動)
"importance": 1, # 優先級(1:高、2:中、3:低)
"estimated_exec_duration": 3, # 預計執行時間(分鐘)
"status": 7, # 用例狀態(1:草稿、2:待評審、3:評審中、4:重作、五、廢棄、6:feature、7:終稿)
"steps": [ # 測試步驟列表
{
"step_number": 1, # 編號
"actions": "測試步驟1", # 步驟內容
"expectedresults": "預期結果1", # 預期結果
"execution_type": 1 # 執行類型(1:手動,2:自動)
},
{
"step_number": 2,
"actions": "測試步驟2",
"expectedresults": "預期結果2",
"execution_type": 1
}
],
"product": "我是產品名", # 產品名稱
"suite": "我是模塊名(測試集1)" # 測試集(模塊名)
},
{
"name": "測試用例2",
"version": 1,
"summary": "測試用例2",
"preconditions": "前置條件",
"execution_type": 1,
"importance": 1,
"estimated_exec_duration": 3,
"status": 7,
"steps": [
{
"step_number": 1,
"actions": "測試步驟1",
"expectedresults": "預期結果1",
"execution_type": 1
},
{
"step_number": 2,
"actions": "測試步驟2(預期結果2能夠爲空)",
"expectedresults": "",
"execution_type": 1
},
{
"step_number": 3,
"actions": "測試步驟3",
"expectedresults": "預期結果3",
"execution_type": 1
},
{
"step_number": 4,
"actions": "測試步驟4",
"expectedresults": "預期結果4",
"execution_type": 1
}
],
"product": "我是產品名",
"suite": "我是模塊名(測試集1)"
},
{
"name": "測試用例3(測試步驟和預期結果能夠都爲空)",
"version": 1,
"summary": "測試用例3(測試步驟和預期結果能夠都爲空)",
"preconditions": "無",
"execution_type": 1,
"importance": 2,
"estimated_exec_duration": 3,
"status": 7,
"steps": [ ],
"product": "我是產品名",
"suite": "我是模塊名(測試集1)"
},
{
"name": "測試步驟2(優先級默認爲中)",
"version": 1,
"summary": "測試步驟2(優先級默認爲中)",
"preconditions": "無",
"execution_type": 1,
"importance": 3,
"estimated_exec_duration": 3,
"status": 7,
"steps": [
{
"step_number": 1,
"actions": "測試步驟1",
"expectedresults": "預期結果1",
"execution_type": 1
},
{
"step_number": 2,
"actions": "測試步驟3",
"expectedresults": "",
"execution_type": 1
}
],
"product": "我是產品名",
"suite": "我是模塊名(測試集2)"
},
{
"name": "測試用例3(前置條件默認爲空) 無設置優先級,這裏加入用例標題",
"version": 1,
"summary": "測試用例3(前置條件默認爲空) 無設置優先級,這裏加入用例標題",
"preconditions": "無",
"execution_type": 1,
"importance": 2,
"estimated_exec_duration": 3,
"status": 7,
"steps": [ ],
"product": "我是產品名",
"suite": "我是模塊名(測試集2)"
}
]
複製代碼
from xmind2testcase.utils import get_xmind_testsuite_list
xmind_file = 'docs/xmind_testcase_demo.xmind'
testsuites = get_xmind_testsuite_list(xmind_file)
print(testsuites)
Output:
[
{ # XMind畫布(Sheet)列表
"name": "我是產品名", # 產品名稱
"details": null, # 產品摘要
"testcase_list": [], # 用例列表
"sub_suites": [ # 用例集列表
{
"name": "我是模塊名(測試集1)", # 用例集1名稱(模塊名)
"details": null, # 用例集摘要
"testcase_list": [ # 用例列表
{ # 具體用例
"name": "測試用例1",
"version": 1,
"summary": "測試用例1",
"preconditions": "前置條件",
"execution_type": 1,
"importance": 1,
"estimated_exec_duration": 3,
"status": 7,
"steps": [
{
"step_number": 1,
"actions": "測試步驟1",
"expectedresults": "預期結果1",
"execution_type": 1
},
{
"step_number": 2,
"actions": "測試步驟2",
"expectedresults": "預期結果2",
"execution_type": 1
}
]
},
{
"name": "測試用例2",
"version": 1,
"summary": "測試用例2",
"preconditions": "前置條件",
"execution_type": 1,
"importance": 1,
"estimated_exec_duration": 3,
"status": 7,
"steps": [
{
"step_number": 1,
"actions": "測試步驟1",
"expectedresults": "預期結果1",
"execution_type": 1
},
{
"step_number": 2,
"actions": "測試步驟2(預期結果2能夠爲空)",
"expectedresults": "",
"execution_type": 1
},
{
"step_number": 3,
"actions": "測試步驟3",
"expectedresults": "預期結果3",
"execution_type": 1
},
{
"step_number": 4,
"actions": "測試步驟4",
"expectedresults": "預期結果4",
"execution_type": 1
}
]
},
{
"name": "測試用例3(測試步驟和預期結果能夠都爲空)",
"version": 1,
"summary": "測試用例3(測試步驟和預期結果能夠都爲空)",
"preconditions": "無",
"execution_type": 1,
"importance": 2,
"estimated_exec_duration": 3,
"status": 7,
"steps": []
}
],
"sub_suites": [] # 用例集中能夠包含子用例集(目前只要產品類別下有用例集)
},
{
"name": "我是模塊名(測試集2)", # 用例集2名稱(模塊名)
"details": "測試集摘要(詳情)",
"testcase_list": [
{
"name": "測試步驟2(優先級默認爲中)",
"version": 1,
"summary": "測試步驟2(優先級默認爲中)",
"preconditions": "無",
"execution_type": 1,
"importance": 3,
"estimated_exec_duration": 3,
"status": 7,
"steps": [
{
"step_number": 1,
"actions": "測試步驟1",
"expectedresults": "預期結果1",
"execution_type": 1
},
{
"step_number": 2,
"actions": "測試步驟3",
"expectedresults": "",
"execution_type": 1
}
]
},
{
"name": "測試用例3(前置條件默認爲空) 無設置優先級,這裏加入用例標題",
"version": 1,
"summary": "測試用例3(前置條件默認爲空) 無設置優先級,這裏加入用例標題",
"preconditions": "無",
"execution_type": 1,
"importance": 2,
"estimated_exec_duration": 3,
"status": 7,
"steps": []
}
],
"sub_suites": []
}
]
}
]
複製代碼
以上(1)TestCase數據、(2)TestSuite數據的獲取,實際上是基於**XMind**這個工具,對XMind文件進行解析和數據提取,而後轉換而來。 這個工具是在設計XMind2TestCase時,針對XMind單獨抽取出來的庫,提供了XMind思惟導圖建立、解析、更新的一系列方法。使用它能夠直接將XMind文件轉換爲JSON數據:
import xmind
xmind_file = 'docs/xmind_testcase_demo.xmind'
workbook = xmind.load(xmind_file)
data = workbook.getData()
print(data)
Output:
[
{ # XMind畫布(sheet)列表
"id": "7hmnj6ahp0lonp4k2hodfok24f", # 畫布ID
"title": "畫布 1", # 畫布名稱
"topic": { # 中心主題
"id": "7c8av5gt8qfbac641lth4g1p67", # 主題ID
"link": null, # 主題上的超連接信息
"title": "我是產品名", # 主題名稱
"note": null, # 主題上的備註信息
"label": null, # 主題上標籤信息
"comment": null, # 主題上的批註(評論)信息
"markers": [], # 主題上的圖標信息
"topics": [ # 子主題列表
{
"id": "2rj4ek3nn4sk0lc4pje3gvgv9k",
"link": null,
"title": "我是模塊名(測試集1)", # 子主題1
"note": null,
"label": null,
"comment": null,
"markers": [],
"topics": [ # 子主題下的子主題列表
{
"id": "3hjj43s7rv66uncr1srl3qsboi",
"link": null,
"title": "測試用例1",
"note": "前置條件\n",
"label": "手動(執行方式默認爲手動)",
"comment": null,
"markers": [
"priority-1"
],
"topics": [
{
"id": "3djn37j1fdc6081de319slf035",
"link": null,
"title": "測試步驟1",
"note": null,
"label": null,
"comment": null,
"markers": [],
"topics": [
{
"id": "7v0f1152popou38ndaaamt49l5",
"link": null,
"title": "預期結果1",
"note": null,
"label": null,
"comment": null,
"markers": []
}
]
},
{
"id": "2srtqqjp818clkk1drm233lank",
"link": null,
"title": "測試步驟2",
"note": null,
"label": null,
"comment": null,
"markers": [],
"topics": [
{
"id": "4jlbo280urmid3qkd01j7h8jnq",
"link": null,
"title": "預期結果2",
"note": null,
"label": null,
"comment": null,
"markers": []
}
]
}
]
},
...
]
},
...
]
}
}
]
複製代碼
每次在 __ about __.py 更新版本號後,運行如下命令,實現自動化更新打包上傳至 PYPI ,同時根據其版本號自動打 Tag 並推送到倉庫:
python3 setup.py pypi
複製代碼
XMind2TestCase 工具的產生,受益於如下四個開源項目,並在此基礎上擴展、優化,受益不淺,感恩!
得益於開源,也將堅持開源,併爲努力開源貢獻本身的點滴之力。後續,將繼續根據實際項目須要,按期進行更新維護, 歡迎大夥的使用和意見反饋,謝謝!
(若是本項目對你有幫助的話,也歡迎 star )