利用EXCEL + VBA 进行遍历测试
- 表格中可以列举多个输入,非常适合遍历类型的单元测试
- 手动或通过规则生成不同的输入参数
- 后台依次调用被测单元处理输入参数
- 然后在批量处理输出结果
举个实际的例子
- 某个插值算法的测试
- 插值算法是这样要求的
示例:要输出的文件名 输入点坐标集(X,Y,Z,END,Time,Mode) 输入点数 插值步长 轨迹规划模式
"Result.csv" 250 0 512 0 0 1 250 0 212 0 30 1 2 2 0
-
设计下面的表结构
- 每行为输出
- 行末自动生成输出文件名称
- 按钮用于启动调用
- 根据测试需要指定不同的CASE
附:VBA代码
Function genItem(lineN As Long, actSheet As Worksheet)
Dim fullPath As String
Dim fileName As String
Dim inputPara As String
Dim shellArg As String
Dim i As Integer
fileName = ThisWorkbook.Path + "\output\file" + CStr(lineN) + ".csv"
fullPath = ThisWorkbook.Path + "\\" + "TrajectoryManager.exe"
inputPara = fileName
For i = 1 To 15
inputPara = inputPara + " " + CStr(actSheet.Cells(lineN, i))
Next i
shellArg = fullPath + " " + inputPara
Shell (shellArg)
'Debug.Print (shellArg)
'Sleep (5000)
genItem = "file" + CStr(lineN) + ".csv"
End Function
Sub genInterp()
Dim i As Long
Dim actSheet As Worksheet
Set actSheet = ThisWorkbook.ActiveSheet
For i = 2 To 1000
If (actSheet.Cells(i, "A") <> "") Then
With Range(actSheet.Cells(i, "A"), actSheet.Cells(i, "Q"))
.Interior.Color = vbYellow
End With
actSheet.Cells(i, "Q") = genItem(i, actSheet)
With Range(actSheet.Cells(i, "A"), actSheet.Cells(i, "Q"))
.Interior.ColorIndex = xlNone
End With
End If
Next i
Set actSheet = Nothing
End Sub