Testing: error types and test data

Computer Science · Programming fundamentals

Question 1 of 10

0

    A programmer adds print statements to see variable values as the program runs. Why?

    Stuck? Read the explanation

    Unlocks at a streak of 5 correct answers in a row.

    Print a free worksheet (PDF)

    Embed this practice on your site or class page

    Paste this HTML into your page. Students practise right there; it is free and needs no account.

    Testing: error types and test data explained

    Testing checks that a program does what it is meant to do. Test data is chosen to cover the different situations a program must handle, and each test has an expected result, which is written down before the test is run.

    There are three kinds of test data:

    • Normal data: typical valid values that the program should accept.
    • Boundary (extreme) data: values at the edges of the valid range, such as the smallest and largest allowed values.
    • Erroneous data: invalid values, such as values outside the range or the wrong data type, which the program should reject.

    Errors in a program are of three main kinds:

    • Syntax errors break the rules of the language, and the compiler or interpreter reports them before the program runs.
    • Logic errors let the program run but give wrong results, for example a comparison using the wrong operator.
    • Runtime errors cause the program to crash while it runs, for example dividing by zero.

    Worked example

    A program accepts a mark from 0 to 100 and outputs a pass when the mark is 50 or more. Choose test data.

    1. Normal: 72, expected pass.
    2. Boundary: 0 and 100, expected fail and pass. Also 49 (fail) and 50 (pass), which test whether the comparison is correct.
    3. Erroneous: -5 and 101, expected rejection. Also "fifty", expected rejection because the data type is wrong.

    If the program contains IF mark = 50 instead of IF mark >= 50, the value 72 would produce no pass. That is a logic error, and the boundary test catches it.

    What you will practise

    112 multiple-choice questions (Easy, Medium, Hard). Each answer is followed by an explanation.

    Example questions

    • What is a syntax error?
    • What is a logic error?
    • What is a runtime error?
    • Which type of test data is valid data that a program should accept and process correctly, typical of what a user would enter?
    • Boundary test data consists of…
    • Erroneous (invalid) test data is…
    • What is the purpose of final testing?
    • Black box testing means…

    …and 104 more.