All Tests run ok, Results are shown

This commit is contained in:
Christof Thalhofer 2016-09-21 10:25:39 +02:00
parent 71fc541075
commit 44442850b0
18 changed files with 285 additions and 110 deletions

View File

@ -1,5 +1,6 @@
[Component]
Key=gb.deg.unit
Version=0.0.7
Version=0.1.0
State=2
Authors=Christof Thalhofer
Needs=XML

133
.info
View File

@ -1,3 +1,57 @@
#ATestContainer
C
'This abstract class identifies TestContainer classes. TestContainers are a
'classes that hold different test case methods.
Name
r
s
CaseNames
p
String[]
Case
p
ITestCase
'The current test case
Result
p
TestResult
R
p
TestResult
Debug
p
b
_new
m
[(ShowDebug)b]
RunCase
m
(oCase)ITestCase;(oTestResult)TestResult;
SetupEach
m
TearDownEach
m
SetupContainer
m
TearDownContainer
m
#CRunner
C
@ -15,7 +69,7 @@ m
'Show the Test Runner Form
PrintResult
m
M
(Res)TestResult;
RunTests
@ -47,7 +101,7 @@ s
Container
r
TestContainer
ATestContainer
#TestCase
ITestCase
@ -64,13 +118,13 @@ s
'Name of the test case
Container
r
TestContainer
ATestContainer
'Reference to the test container containing the test method to be executed.
_new
m
(sName)s(oTestContainer)TestContainer;
(sName)s(oTestContainer)ATestContainer;
'Initializes the TestCase. Used in lieu of a constructor.
Run
m
@ -80,53 +134,6 @@ CountTestCases
m
i
#TestContainer
C
Name
r
s
CaseNames
p
String[]
Case
p
ITestCase
Result
p
TestResult
Debug
p
b
_new
m
[(ShowDebug)b]
RunCase
m
(oCase)ITestCase;(oTestResult)TestResult;
SetupEach
m
TearDownEach
m
SetupContainer
m
TearDownContainer
m
#TestError
C
@ -414,22 +421,34 @@ m
AddNewTestCase
m
(sName)s(oTestContainer)TestContainer;
(sName)s(oTestContainer)ATestContainer;
'Create a new test case and add it to the suite.
AddAllTestCases
m
(oTestContainer)TestContainer;
(oTestContainer)ATestContainer;
'Create all test cases that are contained in the specified TestContainer and add them to the suite.
#_GuTestErrorsAndFailures
TestContainer
ATestContainer
C
TestStringFailure
m
TestLongFailure
m
TestAddError
m
TestAddTrace
m
#_GuTestExample1
TestContainer
ATestContainer
C
SetupEach
m
@ -448,7 +467,7 @@ m
#_GuTestExample2
TestContainer
ATestContainer
C
SetupContainer
m
@ -479,7 +498,7 @@ m
#_GuTestIntentionalError
TestContainer
ATestContainer
C
TestError
m

2
.list
View File

@ -1,8 +1,8 @@
ATestContainer
CRunner!
ITest
ITestCase
TestCase
TestContainer
TestError
TestErrors
TestParameter

View File

@ -2,7 +2,7 @@
# Compiled with Gambas 3.9.90
Title=gb.deg.unit
Startup=FmRunner
Version=0.0.7
Version=0.1.0
Component=gb.image
Component=gb.qt4
Component=gb.form
@ -10,9 +10,11 @@ Component=gb.debug
Component=gb.pcre
Component=gb.qt4.ext
Description="Gambast Unittest, fork from ComUnit\nhttp://comunit.sourceforge.net"
Authors="Christof Thalhofer"
TabSize=4
Language=de
Type=Library
ControlPublic=1
ModulePublic=1
Vendor=Deganius
Packager=1

View File

@ -10,6 +10,9 @@ Geometry=[59,354,255,280]
[DebugWindow/$Result.Failures]
Geometry=[202,70,224,280]
[DebugWindow/$Suite]
Geometry=[131,77,224,280]
[DebugWindow/$TestCaseNames]
Geometry=[137,230,224,280]
@ -43,6 +46,9 @@ Geometry=[188,56,224,280]
[DebugWindow/Container]
Geometry=[118,131,433,280]
[DebugWindow/ContainerNames]
Geometry=[328,42,224,280]
[DebugWindow/CurrentContainer]
Geometry=[188,56,224,280]
@ -116,7 +122,13 @@ Geometry=[311,89,545,280]
Geometry=[325,103,545,280]
[DebugWindow/Res.Errors.Items]
Geometry=[339,117,545,280]
Geometry=[121,331,545,280]
[DebugWindow/Res.Errors.Items[0]]
Geometry=[159,492,545,280]
[DebugWindow/Res.Errors.Items[0].TestCase]
Geometry=[173,506,545,280]
[DebugWindow/Res.Failures]
Geometry=[325,103,545,280]
@ -255,15 +267,19 @@ Path="gb.deg.unit.gambas"
[OpenFile]
File[1]=".src/TestRunner/FmRunner.form"
File[2]=".src/TestRunner/FmRunner.class:45.148"
File[3]=".src/TestMyself/GuTestExample1.class:0.33"
File[4]=".src/TestSuite/TestSuite.class:41.27"
Active=8
Count=8
File[5]=".src/TestSuite/ITestCase.class:0.17"
File[6]=".src/TestSuite/TestCase.class:31.44"
File[7]=".src/TestSuite/ITest.class:35.13"
File[8]=".src/TestRunner/MRunner.module:14.83"
File[2]=".src/TestRunner/FmRunner.class:25.97"
File[3]=".src/TestRunner/FmRunnerResult.form"
File[4]=".src/TestRunner/FmRunnerResult.class:0.94"
Active=4
Count=12
File[5]=".src/TestRunner/CRunner.class:7.27"
File[6]=".src/TestSuite/TestSuite.class:13.27"
File[7]=".src/TestSuite/TestError.class:0.0"
File[8]=".src/TestSuite/TestErrors.class:0.52"
File[9]=".src/TestMyself/_GuTestErrorsAndFailures.class:3.27"
File[10]=".src/TestMyself/_GuTestExample1.class:9.33"
File[11]=".src/TestSuite/TestResult.class:7.101"
File[12]=".src/TestSuite/TestContainer.class:8.61"
[Watches]
Count=0

View File

@ -1,10 +1,28 @@
' Gambas class file
Export
Inherits TestContainer
Inherits ATestContainer
Public Sub TestStringFailure()
Me.Result.AssertEqualsString("Lisa", "Paul", "Strings should be equal")
End
Public Sub TestLongFailure()
Me.Result.AssertEqualsLong(2, 3)
End
Public Sub TestAddError()
Me.Result.AddError(12333, Me.Name, "I wanted a TestAddError")
End
Public Sub TestAddTrace()
Me.Result.AddTrace("This is a trace message")
End

View File

@ -1,6 +1,6 @@
' Gambas class file
Inherits TestContainer
Inherits ATestContainer
Export
Public Sub SetupEach()

View File

@ -1,6 +1,6 @@
' Gambas class file
Inherits TestContainer
Inherits ATestContainer
Export
Public Sub SetupContainer()

View File

@ -1,6 +1,6 @@
' Gambas class file
Inherits TestContainer
Inherits ATestContainer
Export
Public Sub TestError()
@ -17,4 +17,4 @@ Public Sub TestError()
Try a = 2 * 3
Me.Result.AssertError(Error.Code, Error.Text, 26, "Intentional Failure. If this is a failure, then all is ok.")
End
End

View File

@ -25,7 +25,7 @@ Public Sub ShowRunnerForm()
End
Public Sub PrintResult(Res As TestResult)
Static Public Sub PrintResult(Res As TestResult)
Dim Errs As TestErrors
Dim Fails As TestErrors
@ -70,7 +70,7 @@ End
Public Sub RunTests(Result As TestResult, Optional ContainerName As String, Optional CaseName As String, Optional ShowDebug As Boolean)
Dim Container As TestContainer
Dim Container As ATestContainer
If ContainerName = Null Then
If CaseName = Null Then

View File

@ -4,6 +4,7 @@ Property Suite As TestSuite
Private $Suite As TestSuite
Private $Result As TestResult
Private $FmResult As FmRunnerResult
Private $CRunner As CRunner
Public Sub _new()
@ -14,26 +15,31 @@ End
Public Sub Result_AfterStartTest(oTestCase As ITestCase)
Debug "Test " & oTestCase.Name & " started"
End
Public Sub Result_AfterEndTest()
UpdateProgress()
$FmResult.Result = $Result
End
Public Sub Result_AfterAddTrace(sMessage As String)
$FmResult.Result = $Result
End
Public Sub Result_AfterAddError(oError As TestError)
$FmResult.Result = $Result
End
Public Sub Result_AfterAddFailure(oError As TestError)
$FmResult.Result = $Result
End
Sub UpdateProgress()
@ -43,7 +49,7 @@ Sub UpdateProgress()
Runs.Add($Result.CountRunnedTests)
Runs.Add($Suite.CountTestCases())
$FmResult.Runs = Runs
Wait 0.01
Wait 0.4
End
@ -82,7 +88,7 @@ Sub FillCboTests(Optional TestContainerName As String)
Dim ContainerNames As String[]
Dim TestNames As New String[]
Dim C As TestContainer
Dim C As ATestContainer
Dim i As Integer
TestNames.Add("All Test Cases")
@ -114,16 +120,19 @@ End
Sub FillTabs()
Me.TabPanel1.Count = 1
Me.TabPanel1.Arrangement = Arrange.Fill
$FmResult = New FmRunnerResult(Me.TabPanel1)
With $FmResult
.Expand = True
.Show
End With
Me.TabPanel1.Show
Me.TabPanel1.Index = 0
With Me.TabPanel1
.Count = 1
.Arrangement = Arrange.Fill
.Show
.Index = 0
.Text = "Results"
End With
End
@ -145,7 +154,7 @@ Public Sub CboContainers_Change()
Dim ContainerName As String
If CboContainers.Index > 0 Then
ContainerName = CRunner.GetAllTestContainerNames()[CboContainers.Index - 1]
ContainerName = $CRunner.GetAllTestContainerNames()[CboContainers.Index - 1]
Endif
FillCboTests(ContainerName)
@ -161,9 +170,10 @@ End
Sub RunTests()
Dim ContainerName, CaseName As String
Dim CRunner As New CRunner
$Suite = CRunner.Suite
$CRunner = New CRunner
$Suite = $CRunner.Suite
' ------------------------------------------------- Container name
If CboContainers.Index > 0 Then
@ -175,8 +185,8 @@ Sub RunTests()
CaseName = CboTestCases.List[CboTestCases.Index]
Endif
CRunner.RunTests($Result, ContainerName, CaseName)
CRunner.PrintResult($Result)
$CRunner.RunTests($Result, ContainerName, CaseName)
$CRunner.PrintResult($Result)
$Result = New Testresult As "Result"
End

View File

@ -2,6 +2,7 @@
'' Store Runs[0] = number if done, Runs[1] = count of tests
Property Runs As Integer[]
Property Result As TestResult
Private Function Runs_Read() As Integer[]
@ -18,3 +19,98 @@ Private Sub Runs_Write(Value As Integer[])
Me.LblRuns.Text = "Runs: " & done & "/" & all
End
Private Function Result_Read() As TestResult
End
Private Sub Result_Write(Res As TestResult)
Dim Errs As TestErrors
Dim Fails As TestErrors
Dim Err As TestError
Dim Fail As TestError
' Dim C As Class
'TS.Run(Res)
Errs = Res.Errors
Fails = Res.Failures
Me.LblErrors.Text = "Errors: " & Errs.Count
Me.LblFailures.Text = "Failures: " & Fails.Count
FillGrid(Res)
If Errs.Count > 0 Or If Fails.Count > 0 Then
Me.LblTestName.Text = "No success!"
Else
Me.LblTestName.Text = "Success!"
Endif
Wait
End
Sub FillGrid(Res As TestResult)
Dim err As TestError
Dim fail As TestError
Dim i, j, rheight As Integer
Dim rowcount As Integer
rheight = 28
If Res.Errors Then
rowcount = Res.Errors.Count
Endif
If Res.Failures Then
rowcount += Res.Failures.Count
Endif
With Me.GridViewTests
.Clear
.Rows.Count = 0
.Rows[0].H = rheight
.Columns.Count = 3
.Columns[0].Width = 100
.Columns[1].Width = 200
.Columns[2].Width = 300
.Rows.Count = rowcount
If Res.Failures Then
For i = 0 To Res.Failures.Count - 1
.Rows[i].Height = rheight
GridViewTests[i, 0].Text = "Failure"
GridViewTests[i, 1].Text = Res.Failures.Items[i].Source
GridViewTests[i, 2].Text = Res.Failures.Items[i].Description
GridViewTests[i, 0].Background = Color.Yellow
Next
End If
If Res.Errors Then
For i = i To Res.Errors.Count + i
.Rows[i].Height = rheight
GridViewTests[i, 0].Text = "Error"
GridViewTests[i, 0].Foreground = Color.TextForeground
GridViewTests[i, 1].Text = Res.Errors.Items[j].Source
GridViewTests[i, 2].Text = Res.Errors.Items[j].Description
GridViewTests[i, 0].Background = Color.Red
Inc j
Next
Endif
Debug i
End With
' GridView1.Rows.Count = 3
' GridView1.Columns.Width = 52
' GridView1.Rows[1].Height = 52
' GridView1[0, 0].Text = "0,0"
' GridView1[0, 0].Alignment = Align.Right
' GridView1[1, 1].Text = "1,1"
' GridView1[0, 1].Text = "0,1"
' GridView1[1, 0].Picture = Picture["image.png"]
Catch
Error.Clear
End

View File

@ -17,18 +17,26 @@
Expand = True
}
{ HBox1 HBox
MoveScaled(2,50,91,4)
MoveScaled(2,50,91,5)
Spacing = True
Margin = True
Padding = 5
{ LblTestName Label
MoveScaled(0,0,37,4)
Expand = True
Border = Border.Sunken
}
{ LblRuns Label
MoveScaled(34,0,14,4)
MoveScaled(36,0,14,4)
Border = Border.Sunken
}
{ LblFailures Label
MoveScaled(50,0,14,4)
MoveScaled(50,0,21,4)
Border = Border.Sunken
}
{ LblErrors Label
MoveScaled(73,0,14,4)
MoveScaled(72,0,18,4)
Border = Border.Sunken
}
}
}

View File

@ -2,8 +2,11 @@
Export
' This interface identifies TestContainer classes. TestContainers are a
' classes that hold different test case methods.
''' This abstract class identifies TestContainer classes. TestContainers are a
''' classes that hold different test case methods.
'''
''' A TestContainer class hast to inherit ATestContainer, its name has to start
''' with "_GuTest"
Property Read Name As String
@ -11,13 +14,15 @@ Property Read Name As String
Property CaseNames As String[]
Private $CaseNames As String[]
'' The current test case
Property Case As ITestCase
Property Result As TestResult
Property Result, R As TestResult
''Set true for debug messages
Property Debug As Boolean
Private $Case As ITestCase
Private $Result As TestResult
Property Debug As Boolean
Private $Debug As Boolean
Public Sub _new(Optional ShowDebug As Boolean)

View File

@ -12,9 +12,9 @@ Export
Property Read Name As String
' Test container that the test case uses
Property Read Container As TestContainer
Property Read Container As ATestContainer
Private Function Container_Read() As TestContainer
Private Function Container_Read() As ATestContainer
End

View File

@ -10,17 +10,17 @@ Inherits ITestCase
'' Member variables
Private $Name As String
Private $MyContainer As TestContainer
Private $MyContainer As ATestContainer
Private $Debug As Boolean
'' Name of the test case
Property Read Name As String
'' Reference to the test container containing the test method to be executed.
Property Read Container As TestContainer
Property Read Container As ATestContainer
'' Initializes the TestCase. Used in lieu of a constructor.
Public Sub _new(sName As String, oTestContainer As TestContainer)
Public Sub _new(sName As String, oTestContainer As ATestContainer)
$Name = sName
$MyContainer = oTestContainer
@ -80,7 +80,7 @@ Public Function CountTestCases() As Integer
End Function
Private Function Container_Read() As TestContainer
Private Function Container_Read() As ATestContainer
Return $MyContainer

View File

@ -22,7 +22,7 @@ End Sub
Public Sub Run(oTestResult As TestResult, Optional ShowDebug As Boolean)
Dim oTest As ITestCase
Dim CurrentContainer, LastContainer As TestContainer
Dim CurrentContainer, LastContainer As ATestContainer
For Each oTest In $Tests
oTest.Container.Debug = ShowDebug
@ -73,7 +73,7 @@ Public Sub AddTestCase(oTestCase As ITestCase)
End Sub
'' Create a new test case and add it to the suite.
Public Function AddNewTestCase(sName As String, oTestContainer As TestContainer)
Public Function AddNewTestCase(sName As String, oTestContainer As ATestContainer)
Dim test As TestCase
@ -83,7 +83,7 @@ Public Function AddNewTestCase(sName As String, oTestContainer As TestContainer)
End
'' Create all test cases that are contained in the specified TestContainer and add them to the suite.
Public Function AddAllTestCases(oTestContainer As TestContainer)
Public Function AddAllTestCases(oTestContainer As ATestContainer)
Dim sTests As Variant
Dim i As Integer

View File

@ -2,7 +2,7 @@ FmRunner
gb.deg.unit
0
0
0.0.7
0.1.0
gb.image
gb.qt4