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:

Testing1

Testing Evidence:

Testing2 Test 1
Testing3 Test 2
Testing4 Test 3
Testing5 Test 4
Testing6 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:

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 & " more 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:

Testing7

Testing Evidence:

Testing9 Test 1
Testing10 Test 2
Testing11 Test 3
Testing12 Test 4
Testing13 Test 5

Testing Table:

Testing8

Testing Evidence:

Testing14 Test 6
Testing15 Test 7
Testing16 Test 8
Testing17 Test 9
Testing18 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:

| Testing19 | TestingInt3 | |—|—|

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:

Testing20

Testing Evidence:

Testing21 Testing22
Test 1 Test 2
Testing23 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.

| Testing29 |TestingInt4 | |:-:|:-:|

Program code:

Dim totalcost As Decimal
Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.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, FormatCurrency(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 MyBase.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 btnTotal.Click
    txtTotal.Text = FormatCurrency(totalcost)
End Sub

Testing Table:

Testing24

Testing Evidence:

Testing25 Test 1
Testing26 Test 2
Testing27 Test 3
Testing28 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.

TestingInt5

Program code:

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), reorderamount}))
            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 MyBase.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:

Testing30

Testing Evidence:

Testing31 Test 1
Testing32 Test 2
Testing33 Test 3

Example 6 - Updating Staff Information

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.

TestingInt6

Program code:

Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.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.Click
    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.Text & "," & txtYears.Text)
        Else
            updatedfile.WriteLine(details(0) + "," + details(1) + "," + details(2) + "," + details(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:

Testing34

Testing Evidence:

Testing35 Test 1
Testing36 Test 2
Testing37 Test 3