By using expertatexcel.com you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes

Become an Σxpert at Σxcel.com

 


test_routine - code that tests other code

This is useful to test your code.

One way to develop code is called test-driven design (TDD), where you write the tests first and then develop the code to pass the tests.

It helps to start the name of the routine with "sub test_xyz" where the xyz is the name of what you're testing.

sub test_reverse_string()
  lTests = 1
  if reverse_string("adafgawerewr") = "rwerewagfada" then
     lPass = lPass + 1
  End If
  If lPass = lTests then
     Msgbox "Passed all tests"
  else
     Msgbox "Passed " & lPass & " of " & lTests
  End If

End Sub

Function Reverse_string(s)

sNew = ""
for i = len(s) to 1 step -1

   sNew = sNew & mid(s,i,1)

Reverse_string = sNew


End Function