gambas-source-code/comp/src/gb.test/.src/TestSuite/TestCase.class

67 lines
1.5 KiB
Text
Raw Normal View History

' Gambas class file
''' The TestCase class is responsible for executing a specific test case.
''' The test case to be executed is specified through the Name and TestTestModule
''' 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
'' Name of the test case
Property Read Name As String
'' Reference to the TestModule containing the test methods to be executed.
Property Read TestModule As Class
Private $Name As String
Private $MyTestModule As Class
'' Initializes the TestCase. Used in lieu of a constructor.
Public Sub _new(sName As String, TestModule As Class)
Assert sName <> Null
$Name = sName
Assert TestModule
$MyTestModule = TestModule
End Sub
'' Name of the test case
Function Name_Read() As String
Assert $Name <> Null
Return $Name
End
'Create the fixture, run the test and collect the results in Track
Public Sub Run()
Assert $MyTestModule
'$MyTestModule.SetupEach
If $MyTestModule.Symbols.Exist("SetupEach") Then
Object.Call($MyTestModule, "SetupEach")
Endif
Object.Call($MyTestModule, Me.name)
If $MyTestModule.Symbols.Exist("TeardownEach") Then
Object.Call($MyTestModule, "TeardownEach")
Endif
Catch
Debug "Unittest stopped with error \"" & Error.Text & "\" caused by " & $MyTestModule.Name & "." & Me.Name & "."
' Quit
End Sub
Private Function TestModule_Read() As Class
Assert $MyTestModule
Return $MyTestModule
End