Break the Code
How programs are made robust and secure: validating input, authenticating users, testing with normal, boundary and erroneous data, and telling a syntax error that stops the program from a logic error that just gives the wrong answer.
Get the method right under pressure
Free interactive practice on the steps that lose marks under exam pressure.
Start revising freeWhat you'll cover
Make it hard to break
A good program does not just work when everything goes right; it stands up to silly input and mistakes. That means checking what users type, confirming who they are, testing it hard, and knowing why it went wrong when it does. This module works through validation, authentication, testing with different kinds of data, and the two main types of error.
Robust code words to know
Learn these before you try to break a program.
Syntax against logic
The two error types differ by what actually happens when you run the code.
Sort by what happens, test on purpose
In the exam, sort errors by what actually happens. If the code will not run at all, it broke a rule of the language, so it is a syntax error. If it runs yet produces the wrong result, the instructions were faulty, so it is a logic error. For testing, choose three kinds of data on purpose: normal data that should pass, boundary data right on the limit, and erroneous data that should be rejected. Then name the validation check that would keep bad input out.
Match the term
- validation
- authentication
- syntax error
- logic error
- checking input is sensible before it is used
- confirming who a user is
- a mistake that stops the program running
- a mistake that gives the wrong output
Match the check
- range check
- length check
- presence check
- type check
- makes sure a number is between two limits
- makes sure an entry has the right number of characters
- makes sure a field is not left empty
- makes sure the data is the right kind, like a number
What kind of error is this?
A program runs without crashing but prints the wrong total. What kind of error is this?
- A logic error
- A syntax error
- No error at all
- A hardware fault
True about robust code
Select the TWO true statements about robust and secure programming.
- A syntax error stops a program from running
- Boundary data tests values right on the edge of what is allowed
- A logic error always stops a program from running
- Validation is only done after a program is completely finished
Count the characters
A login box needs a username of 5 characters and a password of 8 characters. Add the two lengths to find the total number of characters the user types in. What is the answer?
Order the testing steps
Put the steps of testing a program in order, earliest first.
- Write the program
- Choose normal, boundary and erroneous test data
- Run each test and record the result
- Fix any errors the tests reveal
Complete the rules
Checking that input is sensible before it is used is called _____. Confirming who a user is with a username and password is called _____. A mistake that stops a program running is a _____ error. A mistake that lets it run but gives the wrong output is a _____ error.
Spot the validation checks
Tap the TWO examples of validation checks.
- checking a number falls between two limits
- checking a field has not been left empty
- printing a message to the screen
- saving a file to the disk
Name the fault or test
Read each case and choose the best answer.
- A program is missing a closing bracket and will not run at all. What kind of error is this?
- A calculator app runs fine but always adds when it should multiply. What kind of error is this?
- You test an age box by entering an age far outside the allowed range. What kind of test data is this?
Explain robust programming
Explain how a programmer makes a program robust using validation, authentication and testing, and the difference between syntax and logic errors.
- Explain what validation and authentication are
- Explain the three kinds of test data
- Explain the difference between a syntax error and a logic error