5/27/2021 Testing
Testing
Testing
When you complete the testing section of your project you need to make sure your testing table is specific and
attempts to test all possible inputs.
Below are a series of programs and completed testing tables so you can see how you should complete the testing
tables.
Example 1 - Email Address Validation
This program gets the user to enter an email address and it will decide if it is valid or not. The email address must
follow the following format:
start with a string of alphanumeric characters
followed by the @ symbol
another string of alphanumeric characters
followed by a "."
then a string of alphanumeric characters
Program code:
Dim email As String = txtEmail.Text
If Len(email) = 0 Then
MessageBox.Show("INVALID")
Else
Dim pattern As String = "^[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]+$"
Dim emailAddressMatch As Match = Regex.Match(email, pattern)
If emailAddressMatch.ToString = email Then
MessageBox.Show("VALID")
Else
MessageBox.Show("INVALID")
End If
End If
Testing Table:
computing.outwood.com/NEA/vb/testing-vb.html 1/23
5/27/2021 Testing
Testing Evidence:
Test 1
Test 2
Test 3
computing.outwood.com/NEA/vb/testing-vb.html 2/23
5/27/2021 Testing
Test 1
Test 4
Test 5
Example 2 - Grade Calculator
This program gets the user to enter a test score between 0 and 100. It will then say the grade and how many
marks they are off the next grade. The grade boundaries are:
A = 70+
B = 60+
C = 50+
D = 40+
U = <40
Program code:
computing.outwood.com/NEA/vb/testing-vb.html 3/23
5/27/2021 Testing
Dim nextBoundary As Integer
If IsNumeric(txtScore.Text) = False Then
MessageBox.Show("Please enter a number")
Return
ElseIf Int(txtScore.Text) < 0 Or Int(txtScore.Text) > 100 Then
MessageBox.Show("Please enter a number between 0 and 100")
Return
End If
If txtScore.Text >= 70 Then
nextBoundary = 100 - txtScore.Text
MessageBox.Show("That test score is an A grade, you needed " & nextBoundary.ToString & " mor
e marks to gain full marks")
ElseIf txtScore.Text >= 60 Then
nextBoundary = 70 - txtScore.Text
MessageBox.Show("That test score is a B grade, you needed " & nextBoundary.ToString & " more
marks to get an A")
ElseIf txtScore.Text >= 50 Then
nextBoundary = 60 - txtScore.Text
MessageBox.Show("That test score is a C grade, you needed " & nextBoundary.ToString & " more
marks to get an B")
ElseIf txtScore.Text >= 40 Then
nextBoundary = 50 - txtScore.Text
MessageBox.Show("That test score is a D grade, you needed " & nextBoundary.ToString & " more
marks to get an C")
Else
nextBoundary = 40 - txtScore.Text
MessageBox.Show("That test score is a U grade, you needed " & nextBoundary.ToString & " more
marks to get an D")
End If
Testing Table:
Testing Evidence:
computing.outwood.com/NEA/vb/testing-vb.html 4/23
5/27/2021 Testing
Test
1
Test
2
Test
3
Test
4
computing.outwood.com/NEA/vb/testing-vb.html 5/23
5/27/2021 Testing
Test
1
Test
5
Testing Table:
Testing Evidence:
computing.outwood.com/NEA/vb/testing-vb.html 6/23
5/27/2021 Testing
Test 6
Test 7
Test 8
Test 9
computing.outwood.com/NEA/vb/testing-vb.html 7/23
5/27/2021 Testing
Test
10
Example 3 - Speeding Cars
This program reads a file that contains a list of car registration plates and the speed they were captured at going
through a speed camera. The user will enter the speed limit and it will display which of the cars in the file were
speeding. Part of the file cars.csv is shown below:
computing.outwood.com/NEA/vb/testing-vb.html 8/23
5/27/2021 Testing
| |—|—|
Program code:
lstOutput.Items.Clear()
Dim carsdata As New StreamReader("D:\cars.csv")
Dim details As Array
Dim found As Boolean = False
Dim carspeed As Integer = cmbSpeedLimit.Text
While carsdata.EndOfStream = False
details = carsdata.ReadLine.Split(",")
If details(1) > carspeed Then
lstOutput.Items.Add(details(0) & "," & details(1))
found = True
End If
End While
If found = False Then
MessageBox.Show("There were no cars that broke the speed limit of " & cmbSpeedLimit.Text)
End If
Testing Table:
computing.outwood.com/NEA/vb/testing-vb.html 9/23
5/27/2021 Testing
Testing Evidence:
Test 1 Test 2
computing.outwood.com/NEA/vb/testing-vb.html 10/23
5/27/2021 Testing
Test 3
Example 4 - Order Program
This program reads a file that contains a list of products and their prices sold in a shop. The user enters a GTIN
code (barcode) and how many the customer wants. It then calculates the total cost of each item and a grand total
and creates a receipt.
computing.outwood.com/NEA/vb/testing-vb.html 11/23
5/27/2021 Testing
| |:-:|:-:|
Program code:
computing.outwood.com/NEA/vb/testing-vb.html 12/23
5/27/2021 Testing
Dim totalcost As Decimal
Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b
tnCheck.Click
Dim itemcost As Decimal
Dim reader As New StreamReader("D:\products.csv")
Dim productInfo As Array
Dim quantity As Integer = txtQuan.Text
Dim gtin As String = txtGTIN.Text
Dim found As Boolean = False
Do While reader.EndOfStream = False
productInfo = reader.ReadLine.Split(",")
If productInfo(0) = gtin Then
itemcost = productInfo(2) * quantity
lstItems.Items.Add(New ListViewItem({productInfo(0), productInfo(1), quantity, Forma
tCurrency(productInfo(2)), FormatCurrency(itemcost)}))
found = True
totalcost = totalcost + itemcost
End If
Loop
If found = False Then
lstItems.Items.Add(New ListViewItem({txtGTIN.Text, "Product not found"}))
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBas
e.Load
lstItems.Items.Clear()
lstItems.Columns.Add("GTIN Code", 75, HorizontalAlignment.Center)
lstItems.Columns.Add("Description", 200, HorizontalAlignment.Center)
lstItems.Columns.Add("Quantity", 75, HorizontalAlignment.Center)
lstItems.Columns.Add("Cost", 50, HorizontalAlignment.Center)
lstItems.Columns.Add("Total", 50, HorizontalAlignment.Center)
End Sub
Private Sub btnTotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b
tnTotal.Click
txtTotal.Text = FormatCurrency(totalcost)
End Sub
Testing Table:
computing.outwood.com/NEA/vb/testing-vb.html 13/23
5/27/2021 Testing
Testing Evidence:
Test 1
computing.outwood.com/NEA/vb/testing-vb.html 14/23
5/27/2021 Testing
Test 2
Test 3
computing.outwood.com/NEA/vb/testing-vb.html 15/23
5/27/2021 Testing
Test 4
Example 5 - Reorder Program
This program reads a file that contains a list of products and how many there are in stock. If the number in stock is
low, it works out how many need to be reordered and then creates a new file of the products that need to be
reordered as well as how many.
Program code:
computing.outwood.com/NEA/vb/testing-vb.html 16/23
5/27/2021 Testing
Private Sub btnReorder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btnReorder.Click
lstreorder.Items.Clear()
Dim reader As New StreamReader("D:\catalogue.csv")
Dim productinfo As Array
Dim reorderamount As Integer
Do While reader.EndOfStream = False
productinfo = reader.ReadLine.Split(",")
If productinfo(3) < productinfo(4) Then
reorderamount = productinfo(5) - productinfo(3)
lstreorder.Items.Add(New ListViewItem({productinfo(0), productinfo(1), reorderamoun
t}))
Dim reorder As New StreamWriter("D:\reorder.csv", True)
reorder.WriteLine(productinfo(0) & "," & productinfo(1) & "," & reorderamount)
reorder.Close()
End If
Loop
If lstreorder.Items.Count > 0 Then
MessageBox.Show("Reorder file created")
Else
MessageBox.Show("No products need reordering")
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBas
e.Load
lstreorder.Columns.Add("GTIN Code", 75, HorizontalAlignment.Center)
lstreorder.Columns.Add("Description", 200, HorizontalAlignment.Center)
lstreorder.Columns.Add("Reorder Amount", 100, HorizontalAlignment.Center)
End Sub
Testing Table:
Testing Evidence:
computing.outwood.com/NEA/vb/testing-vb.html 17/23
5/27/2021 Testing
Test
1
Test
2
Test
3
Example 6 - Updating Staff Information
computing.outwood.com/NEA/vb/testing-vb.html 18/23
5/27/2021 Testing
This program updates the number of years a member of staff has been working at the school. When the program
runs the user enters their email address, when it finds the person it asks them to enter their number of years
teaching. It will then update the file if the person exists in the file.
Program code:
computing.outwood.com/NEA/vb/testing-vb.html 19/23
5/27/2021 Testing
Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt
nFind.Click
Dim reader As New StreamReader("D:/staff.csv")
Dim details As Array
Dim found As Boolean = False
Do While reader.EndOfStream = False
details = reader.ReadLine.Split(",")
If details(2) = txtEmail.Text Then
txtFirstName.Text = details(0)
txtSurname.Text = details(1)
txtYears.Text = details(3)
found = True
End If
Loop
reader.Close()
If found = False Then
MessageBox.Show("Member of staff not found, please try another email")
End If
End Sub
Private Sub btnUpdate_Click(sender As System.Object, e As System.EventArgs) Handles btnUpdate.Cl
ick
Dim reader As New StreamReader("D:/staff.csv")
Dim details As Array
Do While reader.EndOfStream = False
details = reader.ReadLine.Split(",")
Dim updatedfile As New StreamWriter("D:/staffupdated.csv", True)
If details(2) = txtEmail.Text Then
updatedfile.WriteLine(txtFirstName.Text & "," & txtSurname.Text & "," & txtEmail.Tex
t & "," & txtYears.Text)
Else
updatedfile.WriteLine(details(0) + "," + details(1) + "," + details(2) + "," + detai
ls(3))
End If
updatedfile.Close()
Loop
reader.Close()
My.Computer.FileSystem.DeleteFile("D:\staff.csv")
My.Computer.FileSystem.RenameFile("D:\staffupdated.csv", "staff.csv")
MessageBox.Show("Staff member details updated")
End Sub
Testing Table:
computing.outwood.com/NEA/vb/testing-vb.html 20/23
5/27/2021 Testing
Testing Evidence:
Test
1
computing.outwood.com/NEA/vb/testing-vb.html 21/23
5/27/2021 Testing
Test
2
Test
3
computing.outwood.com/NEA/vb/testing-vb.html 22/23
5/27/2021 Testing
OGAT Computer Science 2017. v1.2
computing.outwood.com/NEA/vb/testing-vb.html 23/23