Skip to content
SPM Tuition
Computer Science · Web and project development

Testing interaction and data validation

Your form works with sensible values, but you have never tested what a careless user types.

Testing means running your project with chosen inputs and comparing what happens with what should happen. Validation testing in particular asks what the page does when the input is wrong, empty or extreme.

This lesson belongs to web and project development. It supports the test plan you write when you plan an original assessed project.

What kinds of test data should I use?

Use four kinds: normal, boundary, invalid and empty. Each one catches a different fault.

Kind Meaning Example for a range of 1 to 5
Normal Typical valid value 3
Boundary On or beside the limit 1, 5, 0, 6
Invalid Wrong type or format “abc”, 2.5
Empty Nothing entered blank

Boundary values matter most for range checks, because a condition such as qty < 5 instead of qty <= 5 fails only at 5.

Worked example: ticket quantity field

A fictional school event page lets a student book 1 to 5 tickets. The rule: the quantity must be a whole number from 1 to 5.

Test Input Expected Actual Result
T1 3 Accepted Accepted Pass
T2 1 Accepted Accepted Pass
T3 5 Accepted Rejected Fail
T4 6 Rejected with message Rejected with message Pass
T5 abc Rejected with message Page shows NaN Fail
T6 blank Rejected with message Accepted as 0 Fail

Three failures show up, and none appears if you only test the value 3. T3 suggests the check uses < 5 where it needs <= 5. T5 and T6 suggest the code never checks that the input is a number or that the box is filled.

After fixing, run all six tests again, not only the failed ones. A change can break a test that passed before.

The mistake: one test and a tick

A weak test set has one normal value and the word “works”.

Weak testing Stronger testing
Type 3, see it work Six inputs across four kinds
No expected result written Expected result written before running
Only re-run the failed test Re-run the whole set after a fix

Write the expected result before you run the test. If you look at the output first, it is easy to decide that whatever appeared was what you wanted.

How do I test interaction, not just input?

Interaction means what the user does: clicking, tabbing, pressing Enter, changing a choice. Treat each action as a test step with an expected response.

For the ticket page, one interaction test is: type 2, press Enter, expect the total to appear without clicking the button. A second is: click the button twice quickly, expect only one booking. Write these in the same table, with steps in the Input column.

Check yourself

A password field accepts 8 to 12 characters. List five test inputs, each with its kind and expected result.

Answer

One good set:

  • 10 characters: normal, accepted.
  • 8 characters: boundary, accepted.
  • 12 characters: boundary, accepted.
  • 7 characters: boundary just outside, rejected with a message.
  • 13 characters: boundary just outside, rejected with a message.

A sixth test with an empty box (empty kind) is worth adding, expecting a message that the field is required.

What to study next

Record tests so someone else can repeat them. Read documenting your own work on an assessed project, then see the small page testing cluster.

For a teacher to review your test table with you, see online one-to-one Computer Science tuition.

Common questions

What is data validation?

Data validation is checking that input is acceptable before the program uses it. Examples are checking that a field is not empty, that a number lies within a range, or that text has the right length. Invalid input should produce a clear message.

What are normal, boundary and invalid test data?

Normal data is a typical valid value. Boundary data sits on the edge of the allowed range, such as the smallest and largest valid values and the values just outside. Invalid data should be rejected, for example letters in a number field.

How many tests are enough?

Enough to cover each requirement with at least one normal, one boundary and one invalid input. For a single range check that is usually five or six tests. The number matters less than covering each kind.

What do I do when a test fails?

Record the actual result, find the cause, change one thing, then run the same test again and record the new result. Keep the failed row in your log, because it shows the testing was real.

Reading your own test table with a teacher in one-to-one Computer Science lessons helps you notice which input types you keep skipping, while you run the tests on your own project.

  • Online one-to-one lessons for your child with an experienced teacher.
  • Your first class is a one-hour trial, from RM50. The fee is agreed before you book.
  • Happy with the teacher? Continue with lessons of about 1.5 hours. If not, ask for another teacher.