在我們的自動(dòng)化測(cè)試實(shí)施工作中,一個(gè)美觀易讀的測(cè)試報(bào)告是必不可少的一部分。而各大框架特別是一些單元測(cè)試框架如junit、maven test等生成的報(bào)告格式都不盡人意。 今天就向大家推薦一個(gè)簡(jiǎn)單易用的報(bào)告生成模板。
要使用它,只需要將模板文件template引入你的自動(dòng)化項(xiàng)目,將自動(dòng)化執(zhí)行結(jié)果的相關(guān)數(shù)據(jù)重寫(xiě)組合為一個(gè)json字串,然后替換模板文件中的${resultData}數(shù)據(jù),最后重寫(xiě)生成自己的html報(bào)告文件即可。
${resultData}數(shù)據(jù)如下
{
"testPass": 3,
"testResult": [
{
"className": "com.test.testcase.TestDemo1",
"methodName": "testDemo",
"description": "測(cè)試DEMO",
"spendTime": "11ms",
"status": "成功",
"log": [
"this is demo!"
]
},
{
"className": "com.test.testcase.TestDemo2",
"methodName": "testDemo",
"description": "測(cè)試DEMO",
"spendTime": "11ms",
"status": "成功",
"log": [
"this is demo!"
]
},
{
"className": "com.test.testcase.TestDemo3",
"methodName": "testDemo",
"description": "測(cè)試DEMO",
"spendTime": "11ms",
"status": "失敗",
"log": [
"this is demo!"
]
}
],
"testName": "20171109132744897",
"testAll": 3,
"testFail": 1,
"beginTime": "2017-11-09 13:27:44.917",
"totalTime": "33ms",
"testSkip": 0
}
生成的測(cè)試報(bào)告如圖

demo.png