Teachers' Portal  /  A-Level Computer Science 9618  /  Software development  /  Types of error and testing methods
Lesson pack · A-Level Computer Science 9618 · 12.3 · AS Level

Types of error and testing methods

Find the faults. Every non-trivial program contains errors when it is first written.

Student lesson Lab, full screen
At a glance

The shape of the lesson

Topic
Software development
Syllabus reference
Cambridge International AS and A Level Computer Science 9618, 12.3
Level
AS Level
Duration
45 minutes, lab-led; stretches to a 60 minute block (see the contingency notes)
Position in topic
Lesson 4 of 5 in Software development; follows State-transition diagrams; leads into Test data and maintenance
Central model
Fig. 1: where each type of error shows itself as a program goes from source code to output
Cooperative structure
Assessment
Stage 1 check and the exam-style plenary from the student lesson, plus the worksheet as the exit task
Learning objectives

By the end of the lesson, learners can

Section by section
  • Three types of error: The type of an error depends on when and how it shows itself (Fig. 1).
  • Exposing and avoiding faults: Each program in the lab has one logic error.
  • Methods of testing: No single method finds every fault, so a test strategy uses several, at different points in development.
Key points to leave on the board
  • Syntax: breaks the language rules; found by the translator.
  • Logic: runs, but wrong result; found by testing or a dry run.
  • Run-time: crashes or hangs while running, e.g. divide by zero.
  • Methods: dry run, walkthrough, white-box, black-box, stub, integration, alpha, beta, acceptance.
The core visual model

One picture every idea returns to

A syntax error breaks the grammar rules of the language, so the translator cannot translate the code. A logic error is a mistake in the algorithm: the program runs but gives the wrong result. A run-time error happens while the program is running and makes it crash or hang, for example dividing by zero or using an array index outside its bounds. Faults are avoided by good design and programming practice and exposed by testing: dry runs, walkthroughs, white-box and black-box testing, stub and integration testing, then alpha, beta and acceptance testing.

Write codeTranslateRunOutput avoid faults syntax errorrun-time errorlogic error good design,clear names,IDE checks breaks the rulesof the language;not translated program crashesor hangs, e.g.divide by zero program runs butthe result iswrong the translator reports syntax errors; only testing and dry runs expose logic errors
Fig. 1: where each type of error shows itself as a program goes from source code to output
Lesson sequence

Forty-five minutes, phase by phase

TimePhaseWhat happens in the roomGrouping
0 to 5 minHook: predictOpen with the question in the title, Find the faults.. Every non-trivial program contains errors when it is first written. Put the figure on the board: it is the one picture every idea in the lesson returns to.Whole class, then pairs
5 to 13 minTeach and check: Three types of errorThe type of an error depends on when and how it shows itself (Fig. 1). Model the worked example Locate, identify, correct on the board, one line at a time.Whole class, then pairs
13 to 21 minTeach and check: Exposing and avoiding faultsEach program in the lab has one logic error. Project tab 4 of the lab (Find the error) and let a student drive it while the class predicts. Your turn: A program to find the average of N numbers crashes when N is 0. Identify the type of error and suggest how to avoid it.Pairs
21 to 30 minTeach and check: Methods of testingNo single method finds every fault, so a test strategy uses several, at different points in development. Model the worked example Choose the method on the board, one line at a time.Cooperative Concept Mapping
30 to 36 minCheckThe four Stage 1 questions from the student lesson, answered on mini whiteboards or by show of fingers. Re-teach the one most get wrong.Individual, then whole class
36 to 43 minPlenaryThe exam-style questions from Stage 2, one at a time: thirty seconds alone, then a random call. The feedback lines in the key give the examiner's wording.Individual, random call
43 to 45 minExit and homeworkSet the worksheet below (6 questions, 21 marks). Learners self-assess against the objectives before they leave.Individual
Timing and contingency

Protect the parts that carry the learning

The sequence carries about fifty minutes of material, so the lab is driven by one student while the class predicts rather than explored freely. Times are a guide.

Protected: the check at 30 minutes. It is the only individual read on whether the key idea landed, and it is not cut.

Cut first if the build overruns: the last check in Methods of testing, never the check or the plenary.

In a 60 minute block: run worksheet questions 1 to 3 in class as a Rally Coach set and model both the hardest worked example and its check live.

Running the cooperative task

Cooperative Concept Mapping

Teams receive the key terms on cards and arrange them on a large sheet, drawing and labelling the links. Compare maps between teams before showing the model map.

The full structure, with its variations and the other twelve, is on the cooperative-learning page.

Examiner traps to pre-empt

What to head off, and how

Trap learners fall intoTeaching move that pre-empts it
A program that crashes is not a logic error.If it stops while running (divide by zero, index out of range), it is a run-time error; if it finishes but gives the wrong answer, it is a logic error.
Alpha and beta are not about version numbers.Alpha testing is done in-house by the developer's staff; beta testing is done by real users outside the company.
Worksheet

Types of error and testing methods: worksheet

6 questions, 21 marks. Written in the style of the papers; no past paper question is reproduced.

NameClassDate
Q1 · explain[3 marks]

Describe a syntax error, a logic error and a run-time error.

Q2 · analysis[6 marks]

The function should return the sum of the integers from 1 to N.

FUNCTION SumTo(N : INTEGER) RETURNS INTEGER
    DECLARE Count, Sum : INTEGER
    Sum ← 1
    Count ← 1
    WHILE Count < N
        Sum ← Sum + Count
        Count ← Count + 1
    ENDWHILE
    RETURN Sum
ENDFUNCTION

The function contains two errors. Identify each error, state its type and write the correction.

Q3 · recall[2 marks]

Give two ways a programmer can avoid making errors when writing code.

Q4 · explain[4 marks]

Explain the difference between white-box testing and black-box testing.

Q5 · explain[3 marks]

A team is developing a program top-down. The main module is written but the modules it calls are not. Explain how stub testing lets the main module be tested now.

Q6 · apply[3 marks]

Describe alpha testing, beta testing and acceptance testing, saying who carries out each.

Answer key and marking notes
Q1 · 3 marks
  • Syntax error: code that breaks the grammar rules of the language, so it cannot be translated.
  • Logic error: an error in the algorithm; the program runs but produces an incorrect result.
  • Run-time error: an error that occurs while the program is running, causing it to crash or hang (e.g. division by zero).
Q2 · 6 marks
  • Sum ← 1 should be Sum ← 0 (logic error).
  • The 1 is counted twice: with N = 3 the code returns 1 + 1 + 2 = 4.
  • WHILE Count < N should be WHILE Count <= N (logic error).
  • Otherwise N itself is never added.
  • Corrected: Sum ← 0 and WHILE Count <= N.
  • Check: N = 3 gives 0 + 1 + 2 + 3 = 6.
Q3 · 2 marks

Any two from: design first with structure charts / pseudocode; use small modules; meaningful identifiers, comments, indentation; use tested library routines; use constants; validate input; use IDE features such as syntax highlighting and auto-complete.

Q4 · 4 marks
  • White-box: the tester can see / uses knowledge of the code.
  • Test data is chosen to test every path / branch through the code.
  • Black-box: the code is not looked at; testing is based on the specification.
  • The actual outputs for given inputs are compared with the expected outputs.
Q5 · 3 marks
  • Each missing module is replaced by a stub: a dummy module with the same name and parameters.
  • The stub outputs a message to show it was called and / or returns a fixed value.
  • So the main module's logic and calls (and parameter passing) can be tested before the real modules exist.
Q6 · 3 marks
  • Alpha: testing of a nearly complete program in-house by the developer's own staff / testers.
  • Beta: a nearly finished version is given to a limited number of real users outside the company, who report faults.
  • Acceptance: the client / end user tests the finished program against the requirements before accepting it.
Quiz

6 multiple-choice questions on this lesson

From the topic question bank. Assign them in the app for a marked score in your gradebook, or run the topic as a class game.

Q11 mark

Scores is declared as ARRAY[1:50] OF INTEGER. While a program is running it tries to read Scores[51] and stops with an error message. What type of error is this?

  • ARun-time error
  • BLogic error
  • CSyntax error
  • DTranslation error
Q21 mark

Which numbered line contains a syntax error?

01  DECLARE Total, Index : INTEGER
02  Total ← 0
03  FOR Index ← 1 TO 10
04      IF Values[Index] > 0
05          Total ← Total + Values[Index]
06      ENDIF
07  NEXT Index

  • ALine 04
  • BLine 03
  • CLine 06
  • DLine 07
Q31 mark

A programmer talks a group of colleagues through her code line by line, so that they can spot any errors. Which testing method is this?

  • AWalkthrough
  • BDry run
  • CWhite-box testing
  • DAlpha testing
Q41 mark

Module CalcTax has not been written yet. To test the main module, a programmer writes:

FUNCTION CalcTax(Pay : REAL) RETURNS REAL
    OUTPUT "CalcTax called"
    RETURN 100.0
ENDFUNCTION
Which testing method is being used?

  • AStub testing
  • BIntegration testing
  • CBeta testing
  • DBlack-box testing
Q51 mark

CountEven should return how many even numbers there are from 1 to N.

01  FUNCTION CountEven(N : INTEGER) RETURNS INTEGER
02      DECLARE Count, Index : INTEGER
03      Count ← 0
04      FOR Index ← 1 TO N
05          IF Index MOD 2 = 1 THEN
06              Count ← Count + 1
07          ENDIF
08      NEXT Index
09      RETURN Count
10  ENDFUNCTION
CountEven(7) returns 4 instead of 3. Which is the error, and what type is it?

  • ALine 05 should test Index MOD 2 = 0: a logic error
  • BLine 04 should be FOR Index ← 0 TO N: a logic error
  • CLine 05 should test Index MOD 2 = 0: a run-time error
  • DLine 03 should be Count ← 1: a syntax error
Q61 mark

What happens when this code is run?

Count ← 1
WHILE Count <> 10
    OUTPUT Count
    Count ← Count + 2
ENDWHILE

  • ACount goes 1, 3, 5, 7, 9, 11 and never equals 10, so the loop never ends: a run-time error
  • BWHILE must be followed by DO in 9618 pseudocode, so it is a syntax error and does not run
  • CIt outputs 1, 3, 5, 7 and then stops one value too early because of the condition: a logic error
  • DIt outputs the odd numbers 1, 3, 5, 7 and 9 and then stops, so there is no error in the code
Quiz key
Q1: A

An index outside the array bounds is found only while the program runs, and it makes the program crash: a run-time error. A logic error lets the program finish with a wrong result. A syntax error, which the translator reports, stops the code being translated at all, and Scores[51] is valid syntax.

Q2: A

In 9618 pseudocode an IF condition must be followed by THEN, so line 04 should read IF Values[Index] > 0 THEN. Line 03 is a correct FOR header, line 06 correctly closes the IF with ENDIF, and line 07 correctly ends the FOR loop with NEXT Index.

Q3: A

A walkthrough is the programmer explaining the design or code, step by step, to peers who look for errors. A dry run is working through the code by hand with a trace table. White-box testing runs the program with data chosen to cover every path. Alpha testing is in-house testing of a nearly complete program.

Q4: A

A stub is a simple stand-in for an unwritten module: it shows it was called and returns a fixed value, so the calling module can be tested. Integration testing combines real modules that have already been tested. Beta testing gives a nearly finished program to outside users. Black-box testing compares outputs with the specification for chosen inputs.

Q5: A

Index MOD 2 = 1 is TRUE for odd numbers, so it counts 1, 3, 5, 7 and returns 4. Testing MOD 2 = 0 counts 2, 4, 6, giving 3. The program runs but gives the wrong result, so it is a logic error, not a run-time error. Starting the loop at 0 changes nothing, because 0 is not odd, so the function would still return 4. Count ← 1 would make the result 5, and the original line 03 is valid syntax.

Q6: A

Count only takes odd values, so Count <> 10 is always TRUE and the loop runs for ever: an infinite loop makes the program hang, which is a run-time error. 9618 pseudocode writes WHILE without DO. The loop does not stop at 7, or at 9: after 9, Count becomes 11, which is still not 10.

Lab and demo

What to project

The student lesson embeds these tabs. Open them full screen on the projector; every slider has a drag handle on the stage.

Slides

Slides for this lesson

A projectable deck for every pack is on the way. Until then, present the student lesson full screen: its sections, figure and lab tabs follow the same order as the plan above.

Also for this topic

Everything else you can use

Original work by the TheLucidSTEM team. The worksheet items are written in the style of the papers; no past paper question is reproduced.
Previous lessonState-transition diagrams