Iterative testing while coding

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Iterative testing while coding

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A student writes one subroutine, runs it with some test values, fixes a mistake, then runs it again. What is this called?
A Writing the whole program first and testing it only at the end
B Iterative testing
2. What is the correct order in iterative testing?
A Test, fix, retest
B Fix, write more code, test once at the end
3. When do you move on to the next part of the program?
A When the current part passes its tests
B As soon as you have finished typing the current part
4. Why does iterative testing find errors early?
A Errors cannot happen if the code is tested at the end
B Each small part is tested straight after it is written, so a fault is easy to locate
5. A student fixes an error in a loop and then moves straight on without running it again. Is this iterative testing?
A No, the fix has not been retested
B Yes, fixing the error is enough

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1Iterative testing AWrite the FOR loop, run it, find the error now
2Test, fix, retest BThis leaves all testing to the end, so errors are found late and are harder to locate. Iterative testing tests each small part as it is written.
3Iterative testing finds errors early because each new part of the code is tested straight after it is written CThe repeating cycle used on one part of the code until that part works correctly
4Repeat until the part works: after a fix, the same part is tested again before moving on DThe fix is never retested, so the programmer cannot be sure the part now works or that the fix did not add a new error. The part must be tested again before moving on.
5Write the whole program, then test it only once at the end ETesting each small part of the code as it is written, fixing any errors, then retesting before moving on
6Find an error, fix it, then move straight on to the next part FREPEAT Test the part Fix any errors UNTIL Part works

Definitions

Iterative testing

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
REPEAT // test the part, then fix any errors _____ PartWorks = TRUE
2.
WHILE PartWorks = _____ DO // fix the error and retest ENDWHILE
3.
IF ActualOutput = ExpectedOutput ____ PartWorks ← TRUE ENDIF
4.
DECLARE Retests : INTEGER Retests ← 0 Retests ← Retests _ 1
5.
IF ErrorsFound _ 0 THEN // fix the error, then retest ENDIF

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A // Write one small part
B // Test that part now
C // Fix errors, then move on
D // Move on when it works
Question 2
A Total ← 0
B FOR Count ← 1 TO 3
C Total ← Count
D NEXT Count
E OUTPUT Total
Question 3
A // Test only when all is done
B // Fix any errors found
C // Retest the part
D // Then write the next part
Question 4
A INPUT Age
B WHILE Age < 0 AND Age > 120 DO
C OUTPUT "Invalid age"
D INPUT Age
E ENDWHILE
Question 5
A // Test 1: Total of 5 and 7
B // Expected output: 35
C Total ← 5 + 7
D OUTPUT Total

Answer Key

Iterative testing while coding
Section A: Quick Questions
Q1
B — Iterative testing
Q2
A — Test, fix, retest
Q3
A — When the current part passes its tests
Q4
B — Each small part is tested straight after it is written, so a fault is easy to locate
Q5
A — No, the fix has not been retested
Section B: Match the Pairs
Q1
Iterative testing → Testing each small part of the code as it is written, fixing any errors, then retesting before moving on
Q2
Test, fix, retest → The repeating cycle used on one part of the code until that part works correctly
Q3
Iterative testing finds errors early because each new part of the code is tested straight after it is written → Write the FOR loop, run it, find the error now
Q4
Repeat until the part works: after a fix, the same part is tested again before moving on → REPEAT Test the part Fix any errors UNTIL Part works
Q5
Write the whole program, then test it only once at the end → This leaves all testing to the end, so errors are found late and are harder to locate. Iterative testing tests each small part as it is written.
Q6
Find an error, fix it, then move straight on to the next part → The fix is never retested, so the programmer cannot be sure the part now works or that the fix did not add a new error. The part must be tested again before moving on.
Section C: Definitions
Q1
Iterative testing — Testing each small part of the code as it is written, fixing any errors, then retesting before moving on. This finds errors early and repeats until that part works.
Section D: Fill in the Blanks
Q1
REPEAT // test the part, then fix any errors UNTIL PartWorks = TRUE
Q2
WHILE PartWorks = FALSE DO // fix the error and retest ENDWHILE
Q3
IF ActualOutput = ExpectedOutput THEN PartWorks ← TRUE ENDIF
Q4
DECLARE Retests : INTEGER Retests ← 0 Retests ← Retests + 1
Q5
IF ErrorsFound > 0 THEN // fix the error, then retest ENDIF
Section E: Spot the Error
Q1
C — Iterative testing means test, fix, then retest. Moving on straight after fixing skips the retest, so the fix is never checked. It should read: // Fix errors, then retest.
Q2
C — Testing this part gives 3 instead of the expected 6, which shows an error. Total is overwritten each time instead of being added to. The fix is Total ← Total + Count, then retest.
Q3
A — Iterative testing tests each small part as it is written, not only at the end. Waiting lets errors build up and makes them harder to find. It should read: // Test each part as written.
Q4
B — Testing with -5 shows the loop never runs. No number is both below 0 and above 120, so AND is never true. The condition needs OR, then the part is retested.
Q5
B — A test needs the correct expected output, or the result can't be judged. 5 + 7 gives 12, not 35, so the expected output should be 12.