Extended Test Script Services Reference

prevnext

TestLog Class


This class lets you log information from test scripts and stubs.


Overview

Extends TSSLog.

The items in this class are members of RTCOMVPLib.TestLog.


Applicability

Commonly used with QualityArchitect.

QualityArchitect is required for use of this class.


TestLog Example

The following example logs a number of status messages about the various stages of a datapool operation.

Function ITestInterface_TestMain(ByVal args As Variant) As Variant

On Error GoTo MoveMoneyPerformScript_OnTestMainError
	 
	 'Declare variables.
	 Dim lPrimeAccount As Long
	 Dim lSecondAccount As Long
	 Dim lAmount As Long
	 Dim lTranType As Long
	 Dim actRet As String
	 Dim expRet As String
	 Dim dp As New TSSDataPool
	 Dim expErr As Variant
	 Dim NumRows As Integer
	 Dim Desc As String
	 Dim Message As String
	 
	 'Set default values
	 NumRows = 0
	 
	 'Initialize test data store and log services
	 tms.LoginToTestRepository
	 tms.StartTestServices "unittests\COM\RQACOMSample Ver 1.0 
	 	 	 (Rational QualityArchitect Sample for COM)\MoveMoneyPerform"
	 
	 'Create Object
	 Dim obj As Object
	 Set obj = CreateObject("RQACOMSample.MoveMoney")
	 
	 'Open Datapool
	 dp.Open "_MoveMoney_Perform_D"
	 
	 'Loop over datapool and perform test.
	 While dp.Fetch
	 	 
	 	 'Keep counter of number of rows fetched.
	 	 NumRows = NumRows + 1
	 	 
	 	 'Get the column data from the datapool.
	 	 lPrimeAccount = CLng(dp.Value("lPrimeAccount"))
	 	 lSecondAccount = CLng(dp.Value("lSecondAccount"))
	 	 lAmount = CLng(dp.Value("lAmount"))
	 	 lTranType = CLng(dp.Value("lTranType"))
	 	 expRet = CStr(dp.Value("expectedReturn"))
	 	 expErr = dp.Value("expectedError")
	 	 
	 	 'Disable Default Error Handler
	 	 On Error Resume Next
	 	 
	 	 'Clear the global error object in case it is set to something.
	 	 Err.Clear
	 	 
	 	 'Call the method under test.
	 	 actRet = obj.Perform(lPrimeAccount, lSecondAccount, 
	 	 	 	 lAmount, lTranType)
	 	 
	 	 'Save the Error info
	 	 Dim actErr As Long
	 	 Dim actErrDesc As String
	 	 actErr = Err.Number
	 	 actErrDesc = Err.Description
	 	 
	 	 'Enable Default Error Handler
	 	 On Error GoTo MoveMoneyPerformScript_OnTestMainError
	 	 
	 	 'Evaluate the result of the method call
	 	 If IsEmpty(expErr) Then
	 	 
	 	 	 If actErr <> 0 Then
	 	 	 	 'Not expecting an error and one occurred.
	 	 	 	 Desc = "Unexpected error" & "," & " " & CStr(actErr) & 
	 	 	 	 	 	 " was raised." & vbCrLf & actErrDesc
	 	 	 	 Log.Message "Unexpected result", TSS_LOG_RESULT_FAIL, Desc
	 	 	 Else
	 	 	 	 'Not expecting an error and none occurred...
	 	 	 	 'Therefore, check the expected expRet = actRet.
	 	 	 	 
	 	 	 	 If (expRet = actRet) Then
	 	 	 	 	 Log.Message "Expected result", TSS_LOG_RESULT_PASS, 
	 	 	 	 	 	 	 "Call to Perform returned expected value"
	 	 	 	 Else
	 	 	 	 	 Log.Message "Unexpected result", TSS_LOG_RESULT_FAIL,
	 	 	 	 	 	 "Call to Perform returned unexpected value, " 
	 	 	 	 	 	 & actRet & "."
	 	 	 	 End If

	 	 	 End If
	 	 	 
	 	 Else
	 	 
	 	 	 'expErr can represent Err.Number or Err.Description
	 	 	 If actErr = expErr Or actErrDesc = expErr Then
	 	 	 	 'Expecting an Error and the one raised matched 
	 	 	 	 'the expected error.
	 	 	 	 Desc = "Expected error" & "," & " " & expErr 
	 	 	 	 	 	 & " was raised."
	 	 	 	 Log.Message "Expected Error", TSS_LOG_RESULT_PASS, Desc
	 	 	 Else
	 	 	 	 'Expecting an Error and either none was raised or...
	 	 	 	 'the one raised was not the one we expected.
	 	 	 	 Desc = "Expected error" & "," & " " & expErr & 
	 	 	 	 	 	 " was not raised."
	 	 	 	 Log.Message "Unexpected error", TSS_LOG_RESULT_FAIL, Desc
	 	 	 End If
	 	 	 
	 	 End If
	 	 
	 Wend
	 
	 If NumRows = 0 Then
	 	 'Datapool did not contain any rows.  Log a warning.
	 	 Desc = "Datapool " & """" & "MoveMoneyPerform" & """" 
	 	 	 	 	 & " is empty."
	 	 Log.Message "Empty Datapool", TSS_LOG_RESULT_WARN, Desc
	 End If
	 
	 'Execution to this point indicates success, so clear 
	 'any handled errors that may have occurred and continue.
	 Err.Clear
	 
	 'Fall through to cleanup.
	 'No Error will be logged because Err.Number now equals zero.

MoveMoneyPerformScript_OnTestMainError:
	 
	 'If an error occurred, log it.
	 If Err.Number <> 0 Then
	 	 Message = "Unexpected error" & "," & " " & CStr(Err.Number) & 
	 	 	 	 " was raised."
	 	 Log.Message Message, TSS_LOG_RESULT_FAIL, Err.Description
	 End If

	 'Close the datapool
	 If Not dp Is Nothing Then
	 	 dp.Close
	 	 Set dp = Nothing
	 End If
	 
	 'Shutdown test data store and log services
	 tms.EndTestServices
	 
End Function

Summary

This class contains the following methods:

Method Description
Message Logs a message.
WriteError Logs an error that occurred during the execution of a test script.
WriteStubError Logs information about an error that occurred during the execution of a QualityArchitect stub.
WriteStubMessage Logs a message relating to the execution of a QualityArchitect stub.

Note: In addition to these methods, you can also use the methods in the TSSLog class, as summarized in the section Logging Class.


TestLog.Message

Logs a message.


Syntax

Message (message As String, [result As Integer], [description As String])

Element Description
message Specifies the string to log.
result Specifies the notification preference regarding the result of the call. Valid values: TSS_LOG_RESULT_NONE (default: no notification), TSS_LOG_RESULT_PASS, TSS_LOG_RESULT_FAIL, TSS_LOG_RESULT_WARN, TSS_LOG_RESULT_INFO. 0 specifies the default.
description Specifies the string to be put in the entry's failure description field.


Example

For examples of this method, see TestLog Example.


TestLog.WriteError

Logs an error that occurred during the execution of a test script.


Syntax

WriteError(hr As Long, Description As String)

Element Description
hr The error to log.
description A description of the error.


Comments

This method logs a Fail result for the test script.

The description appears in the Description area of the Log Event Properties dialog box.


TestLog.WriteStubError

Logs information about an error that occurred during the execution of a QualityArchitect stub.


Syntax

WriteStubError(hr as Long, description As String)

Element Description
hr The error to log.
description A description of the error.


Comments

The description appears in the Description area of the Log Event Properties dialog box.


Example

For an example of this method, see LookUpTable Example.


TestLog.WriteStubMessage

Logs a message relating to the execution of a QualityArchitect stub, and also includes a description of the message.


Syntax

WriteStubMessage(bsMessage As String, Description As String)

Element Description
bsMessage The message to insert into the log.
Description A description of the message. The description lets you expand upon the logged message.


Comments

The message appears in the Log Event column of the LogViewer. The description appears in the Description field of the Log Event Properties dialog box.


Example

For examples of this method, see LookUpTable Example.

prevnext


Rational Test Script Services for Visual Basic Rational Software Corporation
Copyright (c) 2003, Rational Software Corporation http://www.rational.com
support@rational.com
info@rational.com