Scratch Programming
Testing Programs

Introduction

When we write programs, we need to test that they work. For some programs, you can do this just by running the program. For more complex programs, you only spot the problems when you go looking for them.

There are two aspects to testing that we will look at,

  • Removing the bugs from a program we know doesn't work
  • Preparing test data to see whether a program works correctly

Debugging

To remove the problems in a program, you need to complete the following steps,

  • Run the program
  • Check that the bug actually exists by recreating the conditions where you see it
  • Find the problem in the code - follow the instructions yourself and work out what you think should happen
  • Correct the problem you have in the code
  • Run the program again and make sure that the bug is fixed.

Problem 1

This program is supposed to make the cat travel in a complete circle when the space bar is pressed on the keyboard. Nothing seems to happen.

bug1.sb

Download and correct the program. Take a screenshot of your finished script, paste it into a word-processed document and explain what the problem was and how you fixed it.

Problem 2

This space invader program isn't working. When I shoot the aliens, they don't disappear.

bug2.sb

Download and correct the program. Take a screenshot of your finished script, paste it into a word-processed document and explain what the problem was and how you fixed it.

More Challenges

This site contains a number of Scratch programs that have bugs that need fixing. You can download the programs at the bottom of the page.

https://sites.google.com/site/scratchdebugems/debugems-to-share

Preparing Test Data

The Program

Create a system to accept and test a password for certain characteristics.

  • It should be at least 6, and no more than 12 characters long.
  • The system must indicate that the password has failed and why, asking the user to re enter their choice until a successful password is entered.
  • A message to indicate that the password is acceptable must be displayed.
  • Password strength can be assessed against simple criteria to assess its suitability; for example a password system using only upper and lower case alphabetical characters and numeric characters could assess the password strength as:
    • WEAK if only one type used, eg all lower case or all numeric
    • MEDIUM if two types are used
    • STRONG if all three types are used.

For example

hilltop, 123471324, HAHGFD are all WEAK,
catman3 and 123456t are MEDIUM and
RTH34gd is STRONG

A message to indicate the password strength should be displayed after an acceptable password is chosen.

An attempt at this program has been made in Scratch. Your job is to prepare a test plan to check that the program works correctly every time.

Click to download Password program.

What We Test

For this program, we need to check that the following things are working,

  • Passwords with less than 6 characters are rejected
  • Passwords with more than 12 characters are rejected
  • Passwords with 6 - 12 characters are accepted
  • Passwords are correctly identified as weak, medium and strong.

You will need to conduct more than one test for each of these things to make sure that they are working.

When testing programs, we use a test plan, normally written in a table with headings like the following table.

Test No.DataExpected ResultActual ResultComments

The first column allocates a number to each test. This is useful when you have a large number of tests to conduct. In the second column, you choose the input value (the password). The expected result is written down before the test is carried out and the actual result recorded when the test takes place. The comments column is used to list the details of errors and any fixes that have been implemented.

Choosing Your Test Data

The following principles are observed when choosing test data,

Valid Data: You need to test that programs work as they should when the user enters data that is valid - in the form that the program expects.

Invalid Data: You need to test that the program responds correctly to invalid data. In the password program, a password less than 6 characters or more than 12 is invalid.

Boundary Data: In this program, the password must be 6-12 characters in length. The boundaries of this range are 6 and 12. You need to check that passwords of this length are accepted. You also need to check that the program rejects passwords of 5 and 13 characters - the numbers just over the boundary.

Challenge: Complete a full test plan for this program using the template provided.