-
Notifications
You must be signed in to change notification settings - Fork 3
/
clsTestLogger.cls
83 lines (67 loc) · 2.24 KB
/
clsTestLogger.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "clsTestLogger"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'Purpose: This class is a helper class to output the progress of the tests to the VBA Immediate window
'This is an example of how to use for a class called oClassToTest which has an implementation of INameProvider:
' ' Create a new instance of class to test
' Set oClassToTest = New ClassToTest
'
' ' Instantiate clsTestLogger object
' Set objLogger = New clsTestLogger
' objLogger.SetClass oClassToTest
'
' (*** test code written here *** )
'
' Set objLogger = Nothing
Option Explicit
Implements INameProvider
Private moClass As INameProvider
Private Sub Class_Terminate()
Call EndTest
Set moClass = Nothing
End Sub
Private Function INameProvider_GetClassName() As String
INameProvider_GetClassName = "clsTestLogger"
End Function
Public Sub SetClass(ByVal Obj As INameProvider)
Set moClass = Obj
Call StartTest
End Sub
Private Sub StartTest()
Call LogMessage("Starting testing")
End Sub
Private Sub EndTest()
Call LogMessage("End testing")
End Sub
Public Sub PrintMessage(ParamArray vntMessage() As Variant)
' takes in an open ended list of string variables and appends then together as a message to
' output to the immediate window
If IsEmpty(vntMessage) Then
Exit Sub
Else
Dim i As Integer
Dim strAll As String
'concatenate message elements into into one string
For i = LBound(vntMessage) To UBound(vntMessage)
strAll = strAll & IIf(Len(strAll) > 0, " | ", "") & CStr(vntMessage(i))
Next i
'output string to immediate window
If Len(Trim(strAll)) > 0 Then
Call LogMessage(strAll)
End If
End If
End Sub
Private Sub LogMessage(ByVal strMessage As String)
If Not moClass Is Nothing Then
Debug.Print fncGetDateTimeStamp & vbTab & moClass.GetClassName & " : " & strMessage
End If
End Sub
Private Function fncGetDateTimeStamp() As String
fncGetDateTimeStamp = Format(Now, "yyyy-MM-dd hh:mm:ss")
End Function