Automated test generation with AI tools

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

Automated test generation with AI tools

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. An AI tool writes assert calculate_gst(100) == 10 for your function. What should you do before trusting this test?
A Check the expected output by hand to confirm it is correct
B Trust it because the AI wrote it, so it must be correct
2. Which prompt is better for getting a full set of tests from an AI tool?
A Write a test for my function
B Write assert tests for is_valid_age(age) with normal, boundary and invalid values
3. A function accepts marks from 0 to 100. The AI only tests 50, 60 and 75. What is missing?
A Nothing, because three tests is always enough
B Boundary values (0 and 100) and invalid values (-1 and 101)
4. True or false: if the AI-generated assert tests all pass, the module must be correct.
A False: the tests might have wrong expected outputs or miss cases
B True: passing tests prove the code is correct
5. The AI writes assert average([2, 4, 6]) == 5. Is this expected output correct?
A No: (2 + 4 + 6) / 3 is 4, so the assert should expect 4
B Yes: the AI calculated 5 correctly

Match the Pairs

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

Left columnRight column
1assert is_adult(18) == True AAn edge case the AI may have missed, so you add it yourself: an empty list should give a total of 0
2assert calc_total([]) == 0 BThe expected output was trusted without being checked against the requirement, so the test may be wrong
3Ask the AI for normal, boundary and invalid tests, not just one kind CAn AI-drafted boundary test: you must check by hand that 18 should really count as an adult
4Check an AI expected output by hand: 15% of 200 is 30, so this assert is wrong DOnly a normal case is tested, so boundary and invalid cases such as -1, 0 and 120 are missing
5assert get_grade(50) == 'F' # copied from AI, never checked EWrite assert tests for check_age() with normal, boundary and invalid values
6assert is_valid_age(25) == True # only test written Fassert discount(200) == 20

Definitions

assert

Fill in the Blanks

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

1.
______ add(2, 3) == 5
2.
assert add(2, 3) __ 5
3.
# marks run from 0 to 100 assert validMark(_) == True
4.
assert validMark("abc") == _____
5.
assert total([2, 4, 6]) == __

Spot the Error

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

Question 1
A def is_adult(age):
B return age >= 18
C assert is_adult(18) == False
D assert is_adult(17) == False
Question 2
A def grade(mark):
B if mark => 50:
C return "Pass"
D return "Fail"
E assert grade(50) == "Pass"
Question 3
A def square(n):
B return n * n
C assert square(3) == 9
D assert square(-2) == -4
Question 4
A def add(a, b)
B return a + b
C assert add(2, 3) == 5
D assert add(-1, 1) == 0
Question 5
A def first(items):
B return items[0]
C try:
D first()
E except IndexError:
F print("Test passed")

Answer Key

Automated test generation with AI tools
Section A: Quick Questions
Q1
A — Check the expected output by hand to confirm it is correct
Q2
B — Write assert tests for is_valid_age(age) with normal, boundary and invalid values
Q3
B — Boundary values (0 and 100) and invalid values (-1 and 101)
Q4
A — False: the tests might have wrong expected outputs or miss cases
Q5
A — No: (2 + 4 + 6) / 3 is 4, so the assert should expect 4
Section B: Match the Pairs
Q1
assert is_adult(18) == True → An AI-drafted boundary test: you must check by hand that 18 should really count as an adult
Q2
assert calc_total([]) == 0 → An edge case the AI may have missed, so you add it yourself: an empty list should give a total of 0
Q3
Ask the AI for normal, boundary and invalid tests, not just one kind → Write assert tests for check_age() with normal, boundary and invalid values
Q4
Check an AI expected output by hand: 15% of 200 is 30, so this assert is wrong → assert discount(200) == 20
Q5
assert get_grade(50) == 'F' # copied from AI, never checked → The expected output was trusted without being checked against the requirement, so the test may be wrong
Q6
assert is_valid_age(25) == True # only test written → Only a normal case is tested, so boundary and invalid cases such as -1, 0 and 120 are missing
Section C: Definitions
Q1
assert — AI can draft assert tests for a module, but you must check each expected output by hand to be sure it is correct. Also add any normal, boundary or invalid cases it missed.
Section D: Fill in the Blanks
Q1
assert add(2, 3) == 5
Q2
assert add(2, 3) == 5
Q3
# marks run from 0 to 100 assert validMark(0) == True
Q4
assert validMark("abc") == False
Q5
assert total([2, 4, 6]) == 12
Section E: Spot the Error
Q1
C — The AI's expected output is wrong. The function uses >= 18, so age 18 is an adult and the boundary test must expect True. Always check each expected value by hand.
Q2
B — => is not a valid Python comparison operator, so this is a syntax error. It should be >=.
Q3
D — A negative number squared is positive, so the expected output should be 4. An AI tool can get this wrong, so you must check expected outputs by hand.
Q4
A — The function header is missing its colon, which is a syntax error. It should be def add(a, b):
Q5
D — The invalid-input test must pass an empty list. Calling first() with no argument raises TypeError, not the IndexError being tested. It should be first([]).