gambas-source-code/.src/TestCase.class
2015-01-30 07:46:43 +01:00

118 lines
2.4 KiB
Text

' Gambas class file
' Gambas class
' The TestCase class is responsible for executing a specific test case.
' The test case to be executed is specified through the Name and TestContainer
' properties in the class. The Run method will call the appropriate Setup
' and TearDown methods for the test case as well as executing the test case
' method itself.
Inherits ITestCase
' Member variables
Private $Name As String
Private m_oTestContainer As ITestContainer
Private TestCaseCount As Integer
' Initializes the TestCase. Used in lieu of a constructor.
Public Sub Initialize(sName As String, oTestContainer As ITestContainer)
$Name = sName
m_oTestContainer = oTestContainer
End Sub
' Name of the test case
Property Read Name As String
' Reference to the test container containing the test method to be executed.
Property Read TestContainer As ITestContainer
' Name of the test case
Property Read ITestCase_Name As String
' Test container that the test case uses
Property Read ITestCase_TestContainer As ITestContainer
Function ITestCase_Read() As String
Return $Name
End
'Create the fixture, run the test and collect the results in TestResult
Public Sub Run(oTestResult As TestResult)
' Start test
oTestResult.StartTest(Me)
'On Error Resume Next
' Set up test fixture
Try m_oTestContainer.Setup
' Run test
' Check for exceptions if Setup or Test method
If ( Error ) Then
oTestResult.AddError(Error.Code, Error.Where & "::Setup", Error.Text)
Error.Clear
Else
m_oTestContainer.RunTestCase(Me, oTestResult)
End If
' Tear down test fixture
' must ensure that test fixture is properly torn down if any failures have occurred
m_oTestContainer.TearDown
If ( Error ) Then
oTestResult.AddError(Error.Code, Error.Where & "::TearDown", error.Text)
Error.Clear
End If
oTestResult.EndTest
End Sub
Public Function CountTestCases() As Integer
Return 1
End Function
' Interface methods
Private Sub ITest_Run(ByRef oTestResult As TestResult)
Run(oTestResult)
End Sub
Private Function ITest_CountTestCases() As Integer
Return TestCaseCount
End Function
Private Function Name_Read() As String
Return $Name
End
Private Function TestContainer_Read() As ITestContainer
Return m_oTestContainer
End
Function ITestCase_Name_Read() As String
Return $Name
End
Function ITestCase_TestContainer_Read() As ITestContainer
Return m_oTestContainer
End