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

68 lines
1.7 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 TestModule
''' 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.
'' 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
Try Object.Call($MyTestModule, Me.name)
If Error Then
Assert.Fail(Subst$("&1:&2 crashed with error '&3'", $MyTestModule.Name, Me.Name, Error.Text))
Endif
If $MyTestModule.Symbols.Exist("TeardownEach") Then
Object.Call($MyTestModule, "TeardownEach")
Endif
Catch
2020-04-07 16:48:46 +02:00
Assert.BailOut("Test stopped with error \"" & Error.Text & "\" caused by " & $MyTestModule.Name & "." & Me.Name & ".")
Quit 1
End Sub
Private Function TestModule_Read() As Class
Assert $MyTestModule
Return $MyTestModule
End