Small Basic: Program Testing
This article is about program testing for Microsoft Small Basic programming language.
Testing is a important process in developing a program. The purpose of testing is to find issues and bugs before releasing the program. And the test cases (testing items) are better to be designed at the same time of designing the program features. The test cases sometimes may find regression after some changes in the program.
Unit Testing
Unit testing is done in early stage of development, and tests parts of a program such as subroutines. Unit testing is easy to make it automatically.
Following program is a sample program which has unit testing. In this sample, Math_Hex2Dec subroutine is tested with:
- test cases data
- random data
' Math_Hex2Dec Unit Testing
' Version 0.2
' Copyright © 2017 Nonki Takahashi. The MIT License.
' Program ID WCS662-0
title = "Math_Hex2Dec Unit Testing 0.2"
CRLF = Text.GetCharacter(13) + Text.GetCharacter(10)
Not = "True=False;False=True;"
indent = " "
TextWindow.Title = title
TextWindow.WriteLine(title + CRLF)
testCases = "400=1024;FF=255;0d=13;10000=65536;003366=13158;"
nTest = 0
nPass = 0
' testing with test cases
index = Array.GetAllIndices(testCases)
For i = 1 To Array.GetItemCount(testCases)
nTest = nTest + 1
hex = index[nTest]
TextWindow.WriteLine(nTest + ". Math_Hex2Dec(" + hex + ")")
expected = testCases[hex]
Math_Hex2Dec()
result = dec
Test_Expected()
EndFor
' testing with LDMath and random numbers
max = 100
For i = 1 To 4
nTest = nTest + 1
expected = Math.GetRandomNumber(max)
max = max * 10
hex = LDMath.Decimal2Base(expected, 16)
TextWindow.WriteLine(nTest + ". Math_Hex2Dec(" + hex + ")")
Math_Hex2Dec()
result = dec
Test_Expected()
EndFor
Test_Total()
Sub Math_Hex2Dec
' Math | Convert hexadecimal to decimal
' param hex
' return dec
dec = 0
len = Text.GetLength(hex)
_hex = Text.ConvertToUpperCase(hex)
For ptr = 1 To len
dec = dec * 16 + Text.GetIndexOf("123456789ABCDEF", Text.GetSubText(_hex, ptr, 1))
EndFor
EndSub
Sub Test_Expected
' param expected - expected value
' param result - result value
' param indent - indent space if needed
TextWindow.WriteLine(indent + "Expected: " + expected)
TextWindow.WriteLine(indent + "Result: " + result)
TextWindow.Write(indent)
If expected = result Then
nPass = nPass + 1
TextWindow.ForegroundColor = "Green"
TextWindow.WriteLine("PASS" + CRLF)
Else
TextWindow.ForegroundColor = "Red"
TextWindow.WriteLine("FAIL" + CRLF)
EndIf
TextWindow.ForegroundColor = "Gray"
EndSub
Sub Test_Total
TextWindow.ForegroundColor = "Green"
TextWindow.Write("PASS")
TextWindow.ForegroundColor = "Gray"
TextWindow.WriteLine(": " + nPass + "/" + nTest + CRLF)
EndSub
The result will be as follows.
Integration Testing
Integration testing means to test whole program. It is little difficult to make it automatically.
So, for integration testing, it's important to write testing procedure. Following list is a manual test cases for Shapes editor.
- If there are temp.sb or temp.svg, remove them before testing.
- Draw a triangle, save as temp.sb . Run temp.sb and check the shape is a triangle.
- Draw a rectangle, save as temp.svg . Open temp.svg from GIMP and check the shape is a rectangle.
- Open temp.sb, add an ellipse, save as temp.sb . Run temp.sb and check the shapes are a triangle and an ellipse.
- Open temp.sb, delete a triangle, save as temp.svg . Open temp.svg from GIMP and check the shape is an ellipse.
- Open temp.svg, add a line, save as temp.svg . Open temp.svg from GIMP and check the shapes are an ellipse and a line.
- Open temp.svg, delete an ellipse, save as temp.sb . Run temp.sb and check the shape is a line.
Automatic integration testing will be done with internal macro code in the program. Icon Editor is a sample which has internal macro. But user interface such like keyboard and mouse events must be tested manually.
See Also
Additional Resources
- Small Basic Subroutine Library Project (forum)
- BBC Bitesize - Development and testing (for GCSE)