' Gambas class file ''' The TestCase class is responsible for executing a specific test in a testmodule. ''' The test case to be executed is specified through the Name and TestModule ''' properties. 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 Test._InSetup = True Object.Call($MyTestModule, "_SetupEach") Test._InSetup = False 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 Test._InSetup = True Object.Call($MyTestModule, "_TeardownEach") Test._InSetup = False Endif Catch Test.BailOut("Test stopped with error \"" & Error.Text & "\" caused by " & $MyTestModule.Name & "." & Me.Name & ".") End Sub Private Function TestModule_Read() As Class Assert $MyTestModule Return $MyTestModule End Public Function _compare(TC As Testcase) As Integer If Me.TestModule.Name = TC.TestModule.Name Then Return Comp(Me.Name, TC.Name) Endif Return Comp(Me.TestModule.Name, TC.TestModule.Name) End