1Option VBASupport 1 2Option Explicit 3Dim passCount As Integer 4Dim failCount As Integer 5Dim result As String 6 7Function doUnitTest() As String 8result = verify_testDateValue() 9If failCount <> 0 Or passCount = 0 Then 10 doUnitTest = result 11Else 12 doUnitTest = "OK" 13End If 14End Function 15 16 17 18Function verify_testDateValue() as String 19 20 passCount = 0 21 failCount = 0 22 23 result = "Test Results" & Chr$(10) & "============" & Chr$(10) 24 25 Dim testName As String 26 Dim date1, date2 As Date 27 testName = "Test DateValue function" 28 date2 = 25246 29 30 On Error GoTo errorHandler 31 32 date1 = DateValue("February 12, 1969") '2/12/1969 33 TestLog_ASSERT date1 = date2, "the return date is: " & date1 34 35 date2 = 39468 36 date1 = DateValue("21/01/2008") '1/21/2008 37 TestLog_ASSERT date1 = date2, "the return date is: " & date1 38 result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) 39 verify_testDateValue = result 40 41 Exit Function 42errorHandler: 43 TestLog_ASSERT (False), testName & ": hit error handler" 44End Sub 45 46Sub TestLog_ASSERT(assertion As Boolean, Optional testId As String, Optional testComment As String) 47 48 If assertion = True Then 49 passCount = passCount + 1 50 Else 51 Dim testMsg As String 52 If Not IsMissing(testId) Then 53 testMsg = testMsg + " : " + testId 54 End If 55 If Not IsMissing(testComment) And Not (testComment = "") Then 56 testMsg = testMsg + " (" + testComment + ")" 57 End If 58 59 result = result & Chr$(10) & " Failed: " & testMsg 60 failCount = failCount + 1 61 End If 62 63End Sub 64