99 lines
2.6 KiB
Text
99 lines
2.6 KiB
Text
' Gambas class file
|
|
|
|
Export
|
|
''' The TestSuite class represents a suite of different tests to be run. The TestSuite contains
|
|
''' a part-whole hierarchy of objects that implement the ITest interface --
|
|
''' including TestCase objects and other TestSuite objects. Executing the Run method for the
|
|
''' TestSuite will execute all test cases that it contains. The TestSuite class also provides
|
|
''' methods for add all test cases contained in a test container object into the suite.
|
|
|
|
Inherits ITest
|
|
|
|
Private $Tests As ITest[]
|
|
Private $Debug As Boolean
|
|
|
|
Public Sub _new()
|
|
|
|
$Tests = New ITest[]
|
|
|
|
End Sub
|
|
|
|
'' Runs all tests contained within the collection and collects the result in the TestResult parameter.
|
|
Public Sub Run(oTestResult As TestResult, Optional ShowDebug As Boolean)
|
|
|
|
Dim oTest As ITestCase
|
|
Dim CurrentContainer, LastContainer As ATestContainer
|
|
|
|
For Each oTest In $Tests
|
|
oTest.Container.Debug = ShowDebug
|
|
CurrentContainer = oTest.Container
|
|
|
|
If LastContainer Then
|
|
If LastContainer <> CurrentContainer Then
|
|
LastContainer.TearDownContainer
|
|
CurrentContainer.SetupContainer
|
|
Endif
|
|
Else
|
|
CurrentContainer.SetupContainer
|
|
Endif
|
|
|
|
oTest.Run(oTestResult)
|
|
If Error Then
|
|
oTestResult.AddError(Error.Code, Error.Where, Error.Text)
|
|
Try oTest.TestContainer.TearDownEach()
|
|
Error.Clear
|
|
Endif
|
|
LastContainer = CurrentContainer
|
|
Next
|
|
If LastContainer Then
|
|
LastContainer.TearDownContainer()
|
|
Endif
|
|
|
|
End Sub
|
|
|
|
'' Number of test cases contained in the suite
|
|
Public Function CountTestCases() As Integer
|
|
|
|
Return $Tests.Count
|
|
|
|
End Function
|
|
|
|
'' Add a object implementing ITest (either a TestCase or TestSuite) to the suite.
|
|
Public Sub AddTest(oTest As ITest)
|
|
|
|
$Tests.Add(oTest)
|
|
|
|
End Sub
|
|
|
|
'' Add a TestCase to the suite.
|
|
Public Sub AddTestCase(oTestCase As ITestCase)
|
|
|
|
$Tests.Add(oTestCase, Object.Class(oTestCase).Name)
|
|
|
|
End Sub
|
|
|
|
'' Create a new test case and add it to the suite.
|
|
Public Function AddNewTestCase(sName As String, oTestContainer As ATestContainer)
|
|
|
|
Dim test As TestCase
|
|
|
|
test = New TestCase(sName, oTestContainer)
|
|
$Tests.Add(test)
|
|
|
|
End
|
|
|
|
'' Create all test cases that are contained in the specified TestContainer and add them to the suite.
|
|
Public Function AddAllTestCases(oTestContainer As ATestContainer)
|
|
|
|
Dim sTests As Variant
|
|
Dim i As Integer
|
|
|
|
sTests = oTestContainer.CaseNames
|
|
|
|
If sTests Then
|
|
For i = 0 To sTests.Count - 1
|
|
AddNewTestCase(CStr(sTests[i]), oTestContainer)
|
|
Next
|
|
Endif
|
|
|
|
End
|