利用EXCEL + VBA 進行遍歷測試
- 表格中可以列舉多個輸入,非常適合遍歷類型的單元測試
- 手動或通過規(guī)則生成不同的輸入?yún)?shù)
- 后臺依次調(diào)用被測單元處理輸入?yún)?shù)
- 然后在批量處理輸出結(jié)果
舉個實際的例子
- 某個插值算法的測試
- 插值算法是這樣要求的
示例:要輸出的文件名 輸入點坐標集(X,Y,Z,END,Time,Mode) 輸入點數(shù) 插值步長 軌跡規(guī)劃模式
"Result.csv" 250 0 512 0 0 1 250 0 212 0 30 1 2 2 0
-
設計下面的表結(jié)構(gòu)
image.png- 每行為輸出
- 行末自動生成輸出文件名稱
- 按鈕用于啟動調(diào)用
- 根據(jù)測試需要指定不同的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