' *** FRAMEWORK 1 *** ' Unit Testing Framework from http://ptsefton.com/blog/2007/03/13/vba_unit_tests/ ' Example: Assert "Math looks wrong", "5 + 6 = 112" Sub test1Add() Assert "Math looks wrong", add(5, 6) = 11 Assert "Math looks wrong", add(5, 5) = 10 Assert "Math looks wrong", add(1, 1) = 2 Assert "Math looks wrong", add(1, 2) = 2 End Sub Public Sub Assert(ByVal msg As String, ByVal flag As Boolean) If Not flag Then MsgBox msg, vbInformation, "#epicfail": Stop End Sub ' *** FRAMEWORK 2 *** ' Example: If add(5, 6) <> 11 Then Stop Sub test2Add() If add(5, 6) <> 11 Then Stop If add(5, 5) <> 10 Then Stop If add(1, 1) <> 2 Then Stop If add(1, 2) <> 2 Then Stop End Sub ' *** Sample production code *** Function add(x, y) add = x + y End Function
Advertisement
160
pages
Unit Testing in VBA
Advertisement