@@ -17,11 +17,18 @@ Attribute VB_Exposed = False
1717Option Compare Text
1818Option Explicit
1919
20+ Private Const LineSeperatorLen As Long = 40
21+
2022Implements ITestResultReporter
23+ Private m_FileNo As Long
2124
2225Private WithEvents m_TestResultCollector As TestResultCollector
2326Attribute m_TestResultCollector.VB_VarHelpID = -1
2427
28+ Private Sub Class_Terminate ()
29+ CloseFile
30+ End Sub
31+
2532Private Property Set ITestResultReporter_TestResultCollector(ByVal TestResultCollectorToListen As TestResultCollector )
2633 Set TestResultCollector = TestResultCollectorToListen
2734End Property
@@ -30,49 +37,32 @@ Private Property Set TestResultCollector(ByVal TestResultCollectorToListen As Te
3037 Set m_TestResultCollector = TestResultCollectorToListen
3138End Property
3239
33- Private Sub m_TestResultCollector_NewTestResult (ByVal TestResult As AccUnit .ITestResult)
34- '
35- End Sub
36-
3740Private Sub m_TestResultCollector_TestSuiteFinished (ByVal TestSummary As AccUnit .ITestSummary)
3841 PrintSummary TestSummary, True
39- PrintToFile String ( 40 , "#" )
42+ CloseFile
4043End Sub
4144
4245Private Sub m_TestResultCollector_TestSuiteStarted (ByVal TestSuite As AccUnit .ITestSuite)
43- PrintToFile String (40 , "#" )
44- End Sub
45-
46- Private Sub m_TestResultCollector_TestTraceMessage (ByVal Message As String , ByVal CodeCoverageTracker As CodeCoverageTracker )
47- ' If Message Like "* [*][*][*]*" Then
48- ' Message = Replace(Message, vbNewLine, vbTab)
49- ' ElseIf Message Like "* ~~~*" Then
50- ' Message = Replace(Message, vbNewLine, vbTab)
51- ' End If
52- ' PrintToFile Message
53- '
54- ' If Not (CodeCoverageTracker Is Nothing) Then
55- ' If Message Like "*Total*" Then
56- ' PrintToFile CodeCoverageTracker.GetReport()
57- ' End If
58- ' End If
46+ PrintToFile String (LineSeperatorLen, "#" )
47+ PrintToFile Format(Now(), "yyyy-mm-dd hh:nn:ss" )
5948End Sub
6049
6150Private Sub m_TestResultCollector_PrintSummary (ByVal TestSummary As AccUnit .ITestSummary, ByVal PrintTestResults As Boolean )
6251 PrintSummary TestSummary, PrintTestResults
6352End Sub
6453
6554Private Sub PrintSummary (ByVal TestSummary As AccUnit .ITestSummary, ByVal PrintTestResults As Boolean )
55+
6656 If PrintTestResults Then
67- PrintToFile String (40 , "-" )
57+ PrintToFile String (LineSeperatorLen , "-" )
6858 PrintTestDetailSummary TestSummary.GetTestResults
6959 End If
70- PrintToFile String (40 , "-" )
60+ PrintToFile String (LineSeperatorLen , "-" )
7161 PrintToFile "Tests: " & TestSummary.Total
7262 PrintToFile " " , "Passed: " & TestSummary.Passed
7363 PrintToFile " " , "Failed: " & TestSummary.Failed
7464 PrintToFile " " , "Ignored: " & TestSummary.Ignored
75- PrintToFile String (40 , "-" )
65+ PrintToFile String (LineSeperatorLen , "-" )
7666
7767 If TestSummary.Failed + TestSummary.Error > 0 Then
7868 PrintToFile (TestSummary.Failed + TestSummary.Error) & " / " & TestSummary.Total & " failed"
@@ -82,7 +72,7 @@ Private Sub PrintSummary(ByVal TestSummary As AccUnit.ITestSummary, ByVal PrintT
8272 PrintToFile (TestSummary.Ignored) & " / " & TestSummary.Total & " ignored"
8373 End If
8474
85- PrintToFile String (40 , "-" )
75+ PrintToFile String (LineSeperatorLen , "-" )
8676
8777End Sub
8878
@@ -132,9 +122,6 @@ End Sub
132122
133123Private Sub PrintToFile (ParamArray LogItems())
134124
135- Dim FileNo As Long
136- FileNo = FreeFile
137-
138125 Dim LineString As String
139126 Dim i As Long
140127
@@ -143,12 +130,27 @@ Private Sub PrintToFile(ParamArray LogItems())
143130 LineString = LineString & vbTab & LogItems(i)
144131 Next
145132
146- Open LogFilePath For Append As #FileNo
147- Print #FileNo, LineString
148- Close #FileNo
133+ If m_FileNo = 0 Then
134+ OpenFile
135+ End If
149136
137+ Print #m_FileNo, LineString
138+
139+ End Sub
140+
141+ Private Sub OpenFile ()
142+ m_FileNo = FreeFile
143+ Open LogFilePath For Append As #m_FileNo
144+ End Sub
145+
146+ Private Sub CloseFile ()
147+ On Error Resume Next
148+ If m_FileNo <> 0 Then
149+ Close #m_FileNo
150+ m_FileNo = 0
151+ End If
150152End Sub
151153
152154Private Property Get LogFilePath() As String
153- LogFilePath = CurrentDb.Name & ".AccUnit.log"
155+ LogFilePath = CurrentVbProject.FileName & ".AccUnit.log"
154156End Property
0 commit comments