Java和.Net版通用工具类实现--生成自定义Web Html/Excel测试用例和测试报告
一、背景概述
工作中接触到不同的项目测试需求,其中一个是对WEB功能进行测试,采用了Selenium+Junit+Maven+SVN,另一个是对Web Service Json接口进行测试,自己使用C#写了一个自动化测试工具。我希望两者都能生成一样标准格式的测试用例和测试报告,既能展示在Web站点又能得到Excel,于是分别用Java和C#实现了这个工具类--生成自定义Web Html/Excel(CSV)测试用例和测试报告。
二、 Html模板设计
需要替换或追加的内容用变量标示,Html格式自定义,工具类中直接对文本内容进行替换或追加。
两个模板文件ListSample.htm和DetailSample.htm内容分别为:
[html]
<html>
<head>
<title>$ProjectName Test Report</title>
</head>
<body>
<h1>$ProjectName Test Report</h1>
<table border="1" cellspacing="1" cellpadding="8" style="border: #000000; border-style: solid; border-width: 1px">
<tr><td align="right" style="BACKGROUND-COLOR:#333399;COLOR:white;font-weight:bold;" colspan="1">Project Name: </td><td colspan="3">$ProjectName</td></tr>
<tr><td align="right" style="BACKGROUND-COLOR:#333399;COLOR:white;font-weight:bold;">Total: </td><td width="100px">$Total</td>
<td align="right" style="BACKGROUND-COLOR:#333399;COLOR:white;font-weight:bold;">Http Path: </td><td><a href="$HttpPath">$HttpPath</a></td></tr>
<tr><td align="right" style="BACKGROUND-COLOR:#333399;COLOR:white;font-weight:bold;">Passed: </td><td style="color:green;font-weight:bold;">$Passed</td>
<td align="right" style="BACKGROUND-COLOR:#333399;COLOR:white;font-weight:bold;">Code Path: </td><td><a href="$ScriptPath">$ScriptPath</a></td></tr>
<tr><td align="right" style="BACKGROUND-COLOR:#333399;COLOR:white;font-weight:bold;">Failed: </td><td style="color:red;font-weight:bold;">$Failed</td>
<td align="right" style="BACKGROUND-COLOR:#333399;COLOR:white;font-weight:bold;">Test Date: </td><td>$TestDate</td></tr>
<tr><td align="right" style="BACKGROUND-COLOR:#333399;COLOR:white;font-weight:bold;" colspan="1">Summary: </td><td colspan="3">$Summary</td></tr>
</table>
<br />
<table width="90%" border="1" cellspacing="1" cellpadding="8" style="table-layout:fixed;border: #000000; border-style: solid; border-width: 1px ">
<tr style="BACKGROUND-COLOR:#333399;COLOR:white;font-weight:bold;">
<td width="15%">CaseID</td>
<td width="15%"> TaskName </td>
<td width="10%"> TestTime </td>
<td> TestSummary</td>
<td width="10%"> TestResult</td>
<td width="15%"> Comments</td></tr>
<!--<tr><td>$CaseID</td><td>$TaskName</td><td>$TestTime</td><td>$TestSummary</td><td style="font-weight:bold;"><a href="$href"><font color="$color">$TestResult</font></a></td><td>$Comments</td></tr>-->
<html>
<head>
<title>$ProjectName Test Report</title>
</head>
<body>
<h1>$ProjectName Test Report</h1>
<table border="1" cellspacing="1" cellpadding="8" style="border: #000000; border-style: solid; border-width: 1px">
<tr><td align="right" style="BACKGROUND-COLOR:#333399;COLOR:white;font-weight:bold;" colspan="1">Project Name: </td><td colspan="3">$ProjectName</td></tr>
<tr><td align="right" style="BACKGROUND-COLOR:#333399;COLOR:white;font-weight:bold;">Total: </td><td width="100px">$Total</td>
<td align="right" style="BACKGROUND-COLOR:#333399;COLOR:white;font-weight:bold;">Http Path: </td><td><a href="$HttpPath">$HttpPath</a></td></tr>
<tr><td align="right" style="BACKGROUND-COLOR:#333399;COLOR:white;font-weight:bold;">Passed: </td><td style="color:green;font-weight:bold;">$Passed</td>
<td align="right" style="BACKGROUND-COLOR:#333399;COLOR:white;font-weight:bold;">Code Path: </td><td><a href="$ScriptPath">$ScriptPath</a></td></tr>
<tr><td align="right" style="BACKGROUND-COLOR:#333399;COLOR:white;font-weight:bold;">Failed: </td><td style="color:red;font-weight:bold;">$Failed</td>
<td align="right" style="BACKGROUND-COLOR:#333399;COLOR:white;font-weight:bold;">Test Date: </td><td>$TestDate</td></tr>
<tr><td align="right" style="BACKGROUND-COLOR:#333399;COLOR:white;font-weight:bold;" colspan="1">Summary: </td><td colspan="3">$Summary</td></tr>
</table>
<br />
<table width="90%" border="1" cellspacing="1" cellpadding="8" style="table-layout:fixed;border: #000000; border-style: solid; border-width: 1px ">
<tr style="BACKGROUND-COLOR:#333399;COLOR:white;font-weight:bold;">
<td width="15%">CaseID</td>
<td width="15%"> TaskName </td>
<td width="10%"> TestTime </td>
<td> TestSummary</td>
<td width="10%"> TestResult</td>
<td width="15%"> Comments</td></tr>
<!--<tr><td>$CaseID</td><td>$TaskName</td><td>$TestTime</td><td>$TestSummary</td><td style="font-weight:bold;"><a href="$href"><font color="$color">$TestResult</font></a></td><td>$Comments</td></tr>-->其中:
[html] view plaincopyprint?<tr><td>$CaseID</td><td>$Tas
补充:Web开发 , ASP.Net ,