测试用例是怎么写的?
测试用例可以分为基本事件、备选事件和异常事件。设计基本事件的用例,应该参照用例规约(或设计规格说明书),根据关联的功能、操作按路径分析法设计测试用例。而对孤立的功能则直接按功能设计测试用例。基本事件的测试用例应包含所有需要实现的需求功能,覆盖率达100%。设计备选事件和异常事件的用例,则要复杂和困难得多。例如,字典的代码是唯一的,不允许重复。测试需要验证:字典新增程序中已存在有关字典代码的约束,若出现代码重复必须报错,并且报错文字正确。往往在设计编码阶段形成的文档对备选事件和异常事件分析描述不够详尽。而测试本身则要求验证全部非基本事件,并同时尽量发现其中的软件缺陷。可以采用软件测试常用的基该方法:等价类划分法、边界值分析法、错误推测法、因果图法、逻辑覆盖法等设计测试用例。视软件的不同性质采用不同的方法。如何灵活运用各种基该方法来设计完整的测试用例,并最终实现暴露隐藏的缺陷,全凭测试设计人员的丰富经验和精心设计。设计原则测试用例是一个文档,是执行的最小实体。测试用例包括输入、动作、时间和一个期望的结果,其目的是确定应用程序的某个特性是否可正常工作,并且达到程序所设计的结果。以便测试某个程序路径或核实是否满足某个特定需求般在进行测试用例设计前要全面了解被测试产品的功能、明确测试范围(特别是要明确哪些是不需要测试的)、具备基本的测试技术与方法等。测试用例设计一般遵循以下原则: (1)正确性。输入用户实际数据以验证系统是否满足需求规格说明书的要求;测试用例中的测试点应首先保证要至少覆盖需求规格说明书中的各项功能,并且正常。(2)全面性。覆盖所有的需求功能项;设计的用例除对测试点本身的测试外,还需考虑用户实际使用的情况、与其他部分关联使用的情况、非正常情况(不合理、非法、越界以及极限输入数据)操作和环境设置等。(3)连贯性。用例组织有条理、主次分明,尤其体现在业务测试用例上;用例执行粒度尽量保持每个用例都有测点,不能同时覆盖很多功能点,否则执行起来牵连太大,所以每个用例间保持连贯性很重要。(4)可判定性。测试执行结果的正确性是可判定的,每一个测试用例都有相应的期望结果。(5)可操作性。测试用例中要写清楚测试的操作步骤,以及与不同的操作步骤相对应的测试结果。
如何写测试用例
对各个功能模块进行测试点分析,提取测试点再堆测试点进行用例编写。比如对PC端QQ账号的登录模块,提取测试点就有:①正常登陆;②账号为空时点击登录;③密码为空时点击登录;④账号密码都为空时点击登录;⑤密码错误时点击登录 ;⑥找回密码功能是否有效;⑦记住密码功能是否有效;⑧自动登录功能是否有效。编写测试用例该注意:①根据项目的实际情况设计测试用例表格;②用例格式不要生搬硬套;③根据具体情况编写。
QTP用例执行完后怎么将结果导出到excel表格
改写了Report Manager中输出为Excel格式的部分,以方便仅需要Excel格式Report的情况下调用。
可以将代码做成一个单独的Libraries文件(参考附件ExcelReport.txt)
在任何需要输出报告的地方,调用例子如下:
ExcelReport "Pass", "Test Detail A", "Test Remark A"
Option Explicit
'==================================================
' 全局变量
'==================================================
Dim varReportName ' 测试报告文件名
'==================================================
' 常数定义
'==================================================
Const cSheet1Name = "Test_Summary"
Const cSheet2Name = "Test_Result"
'==================================================
' Output Test Result to Excel File
' vStatus 测试状态,分别为Fail, Pass, Warning
' vDetails 测试内容
' vRemarks 测试备注
' Example: ExcelReport "Pass", "Test Detail A", "Test Remark A"
'==================================================
Sub ExcelReport(ByVal vStatus, ByRef vDetails, ByRef vRemarks)
Dim objExcel ' object of Excel
Dim objExcelBook ' object of Excel WorkBook
Dim vActionName ' QTP Test Name
Dim vSummaryRow, vResultRow, vNewAction, vUCaseStatus
vActionName = Environment("TestName" & " - " & Environment("ActionName"
' vActionName = "ExcelReporter - Action "
vUCaseStatus = UCase(vStatus)
If varReportName = Empty Then
varReportName = Environment ("TestDir"& "\" & "测试报告" & Replace(Now,":","") & ".xls"
' varReportName = "D:\QTP\ExcelReporter\" & "测试报告" & Date & ".xls"
Call CreateExcelReport(varReportName)
End If
Set objExcel = CreateObject("Excel.Application")
Set objExcelBook = objExcel.Workbooks.Open(varReportName)
' objExcel.Visible = True 'Debug
' Test Summary Sheet
objExcel.Sheets(cSheet1Name).Select
With objExcel.Sheets(cSheet1Name)
vSummaryRow = .Range("C7").Value + 11
vResultRow = .Range("C8").Value + 2*.Range("C7").Value + 2
vNewAction = False
If .Cells(vSummaryRow - 1, 2).Value vActionName Then ' 新增Action
.Cells(vSummaryRow, 2).Value = vActionName
objExcel.ActiveSheet.Hyperlinks.Add .Cells(vSummaryRow, 2), "", cSheet2Name&"!A"&vResultRow+1, vActionName&" Result"
.Cells(vSummaryRow, 3).Value = vStatus
Select Case vUCaseStatus
Case "FAIL"
.Range("C" & vSummaryRow).Font.ColorIndex = 3
Case "PASS"
.Range("C" & vSummaryRow).Font.ColorIndex = 50
Case "WARNING"
.Range("C" & vSummaryRow).Font.ColorIndex = 5
End Select
vNewAction = True
.Cells(vSummaryRow, 4).Value = 1
.Range("C7").Value = .Range("C7").Value + 1
'Set color and Fonts
.Range("B" & vSummaryRow & "" & vSummaryRow).Borders(1).LineStyle = 1
.Range("B" & vSummaryRow & "" & vSummaryRow).Borders(2).LineStyle = 1
.Range("B" & vSummaryRow & "" & vSummaryRow).Borders(3).LineStyle = 1
.Range("B" & vSummaryRow & ":D" & vSummaryRow).Borders(4).LineStyle = 1
.Range("B" & vSummaryRow & ":D" & vSummaryRow).Interior.ColorIndex = 19
.Range("B" & vSummaryRow).Font.ColorIndex = 53
Else
.Range("D" & vSummaryRow-1).Value = .Range("D" & vSummaryRow-1).Value + 1
End If
If (Not vNewAction) And (vUCaseStatus = "FAIL") Then ' 重复Action Test并且vStatus为Fail
.Cells(vSummaryRow-1, 3).Value = vStatus
.Range("C" & vSummaryRow-1).Font.ColorIndex = 3
End If
If (Not vNewAction) And (vUCaseStatus = "WARNING") Then ' 重复Action Test并且vStatus为Warning
If UCase(.Cells(vSummaryRow-1, 3).Value) = "PASS" Then
.Cells(vSummaryRow-1, 3).Value = vStatus
.Range("C" & vSummaryRow-1).Font.ColorIndex = 5
End If
End If
.Range("C8").Value = .Range("C8").Value + 1
.Range("C5").Value = Time
End With
' Test Result Sheet
objExcel.Sheets(cSheet2Name).Select
With objExcel.Sheets(cSheet2Name)
If vNewAction Then
.Range("A" & vResultRow & ":D" & vResultRow).Interior.ColorIndex = 15
.Range("A" & vResultRow & ":D" & vResultRow).Merge
vResultRow = vResultRow + 1
.Range("A" & vResultRow & ":D" & vResultRow).Merge
.Range("A" & vResultRow & ":D" & vResultRow).HorizontalAlignment = 1
.Range("A" & vResultRow).Value = vActionName
'Set color and Fonts
.Range("A" & vResultRow & ":D" & vResultRow).Interior.ColorIndex = 19
.Range("A" & vResultRow & ":D" & vResultRow).Font.ColorIndex = 53
.Range("A" & vResultRow & ":D" & vResultRow).Font.Bold = True
vResultRow = vResultRow + 1
.Range("A" & vResultRow).Value = "Step "&objExcel.Sheets(cSheet1Name).Range("D" & vSummaryRow).Value
Else
.Range("A" & vResultRow).Value = "Step "&objExcel.Sheets(cSheet1Name).Range("D" & vSummaryRow-1).Value
End If
.Range("B" & vResultRow).Value = vStatus
.Range("C" & vResultRow).Value = vDetails
.Range("D" & vResultRow).Value = vRemarks
Select Case vUCaseStatus
Case "PASS"
.Range("B" & vResultRow).Font.ColorIndex = 50
Case "FAIL"
.Range("A" & vResultRow & ":E" & vResultRow).Font.ColorIndex = 3
Case "WARNING"
.Range("A" & vResultRow & ":E" & vResultRow).Font.ColorIndex = 5
End Select
'Set the Borders
.Range("A" & vResultRow & ":D" & vResultRow).Borders(1).LineStyle = 1
.Range("A" & vResultRow & ":D" & vResultRow).Borders(2).LineStyle = 1
.Range("A" & vResultRow & ":D" & vResultRow).Borders(3).LineStyle = 1
.Range("A" & vResultRow & ":D" & vResultRow).Borders(4).LineStyle = 1
End With
objExcel.Sheets(cSheet1Name).Select
objExcelBook.Save
objExcel.Quit
Set objExcelBook = Nothing
Set objExcel = Nothing
End Sub
'==================================================
' Create Excel Report File
'==================================================
Sub CreateExcelReport(ByRef vFileName)
Dim fso ' object of FSO
Dim objExcel ' object of Excel
Set fso = CreateObject("scripting.FileSystemObject")
Set objExcel = CreateObject("Excel.Application")
If objExcel Is Nothing Then MsgBox "系统未检测到安装了EXCEL!"
objExcel.DisplayAlerts = False
' objExcel.Visible = True 'Debug
' 生成报告并设置格式
If Not fso.FileExists(varReportName) Then
objExcel.Workbooks.Add
' Test Summary Sheet
objExcel.Sheets.Item(1).Select
With objExcel.Sheets.Item(1)
.Name = cSheet1Name
' 设置显示方式
.Columns("A:A").ColumnWidth = 5
.Columns("B:B").ColumnWidth = 35
.Columns("C:C").ColumnWidth = 15
.Columns("D:D").ColumnWidth = 15
.Columns("A:D").WrapText = False
.Columns("C:C").HorizontalAlignment = -4108 ' 4,右对齐;-4108,居中
.Range("C3:C8").HorizontalAlignment = 4
.Range("B10:D10").HorizontalAlignment = -4108
.Range("A:D").VerticalAlignment = -4160
.Range("B2:C2").Merge
.Range("B2:C2").Interior.ColorIndex = 31
.Range("B10:D10").Interior.ColorIndex = 31
.Range("B3:C8").Interior.ColorIndex = 24
.Range("B2:C2").Font.ColorIndex = 19
.Range("B10:D10").Font.ColorIndex = 19
.Range("B3:C8").Font.ColorIndex = 12
.Range("B2:B8").Borders(1).LineStyle = -4119 ' 1,单线;-4115,点线;-4119,双线
.Range("C2:C8").Borders(2).LineStyle = -4119
.Range("B2:C2").Borders(3).LineStyle = -4119
.Range("B8:C8").Borders(4).LineStyle = -4119
.Range("B3:C8").Borders(3).LineStyle = 1
.Range("C3:C8").Borders(1).LineStyle = 1
.Range("B2:B8").Font.Bold = True
.Range("B10:D10").Font.Bold = True
.Range("A:D").Font.Size = 10
.Range("B2").Font.Size = 12
.Range("B10:D10").Font.Size = 12
' 设置单元格内容
.Range("B2").Value = "Results Summary"
.Range("B3").Value = "Test Date:"
.Range("B4").Value = "Test Start Time:"
.Range("B5").Value = "Test End Time:"
.Range("B6").Value = "Test Duration: "
.Range("B7").Value = "Test Actions:"
.Range("B8").Value = "Total Test Steps:"
.Range("C3").Value = Date
.Range("C4").Value = Time
.Range("C5").Value = Time
.Range("C6").Value = "=R[-1]C-R[-2]C"
.Range("C6").NumberFormat = "[h]:mm:ss;@"
.Range("C7").Value = "0"
.Range("C8").Value = "0"
.Range("B10").Value = "Action Name"
.Range("C10").Value = "Status"
.Range("D10").Value = "Test Steps"
' .Columns("B:D").Autofit
' .Range("B11").Select
' objExcel.ActiveWindow.FreezePanes = True
End With
' Test Result Sheet
objExcel.Sheets.Item(2).Select
With objExcel.Sheets.Item(2)
.Name = cSheet2Name
'Set color and Fonts
.Columns("A:A").ColumnWidth = 15
.Columns("B:B").ColumnWidth = 12.5
.Columns("C:D").ColumnWidth = 45
.Columns("C:D").WrapText = True
.Columns("A:B").HorizontalAlignment = -4108 ' 4,右对齐;-4108,居中
.Range("A:D").VerticalAlignment = -4160
.Range("A1:D1").Interior.ColorIndex = 31
.Range("A1:D1").Font.ColorIndex = 19
.Range("A1:D1").Borders(1).LineStyle = 1
.Range("A1:D1").Borders(2).LineStyle = 1
.Range("A1:D1").Borders(3).LineStyle = 1
.Range("A1:D1").Borders(4).LineStyle = 1
.Range("A1:D1").Font.Bold = True
' 设置单元格内容
.Range("A1").Value = "Test Step"
.Range("B1").Value = "Status"
.Range("C1").Value = "Details"
.Range("D1").Value = "Remarks"
' .Range("A2").Select
' objExcel.ActiveWindow.FreezePanes = True
End With
objExcel.ActiveWorkbook.SaveAs vFileName
objExcel.Quit
End If
End Sub