Skip to content
AI Skills Central

Type to search Agent Skills, workflows, tutorials, tools and the glossary.

Tutorial

Getting started with AI test case design

Use a language model to draft test cases for a feature, prompt it for coverage rather than happy paths, and review its ideas like a tester before you automate.

By Updated Beginner20 min hands-on
Bookmark

Bookmarks are kept in your free account, so you can find this page again on any device.

Sign in to bookmark
Quiz at the end
On this page

Language models are good at one part of testing in particular: generating test ideas. Ask well and you get a broad list of cases in seconds, including some you would not have thought of. Ask badly and you get twenty variations of the happy path. Either way, the list is a draft. The skill this tutorial teaches is the combination: prompting for coverage, then reviewing like a tester.

We will work through one small feature, a discount code at checkout, from description to a reviewed set of automated tests.

The feature

Here is the rule, as it might appear in a ticket:

Customers can enter the code SAVE10 at checkout for 10% off the order subtotal. The code is valid only when the subtotal is £50.00 or more. Codes are not case-sensitive. Only one code can be used per order. The discounted total is rounded to the nearest penny.

Simple enough that you can check every suggestion the model makes, which is the point.

1. Describe the behaviour, not the implementation

Give the model the rule, the inputs and anything you know about how users behave. Do not paste the code: you want test ideas based on what the feature should do, not on what the code happens to do.

I'm a tester. Here is a checkout rule I need to test:

<rule>
Customers can enter the code SAVE10 at checkout for 10% off the order subtotal.
The code is valid only when the subtotal is £50.00 or more. Codes are not
case-sensitive. Only one code can be used per order. The discounted total is
rounded to the nearest penny.
</rule>

Inputs: the subtotal (a money amount) and the code (free text typed by the customer).

2. Ask for categories, not just cases

“Write test cases” tends to produce a flat list weighted towards obvious successes. Asking for test design techniques by name gives broader coverage, because each one pushes the model to look at the rule differently:

Using that rule, list test ideas under these headings:
1. Boundary values (for the subtotal and for rounding)
2. Invalid and unusual inputs (for the code field)
3. Rule combinations and state (one code per order, changing the basket after applying)
4. Things the rule does not say but a customer might try

For each idea give: the input, the expected result, and one sentence on why it matters.
Mark any expected result you are inferring rather than reading from the rule with [ASSUMPTION].

The last line is important. Models fill gaps in a specification with plausible guesses. Asking them to flag guesses turns hidden assumptions into questions for the product owner.

A typical response will include things like £49.99 and £50.00, lower-case save10, leading and trailing spaces, the letter O typed instead of a zero, an empty code, applying the code then removing items so the subtotal drops below £50, and trying a second code. Under heading 4 you may see ideas about expired codes or other currencies: useful questions, even if the answer is “out of scope”.

3. Ask for a decision table

For rules with several conditions, a decision table makes gaps obvious:

Now make a decision table with columns: subtotal (below 50 / exactly 50 / above 50),
code (valid / valid different case / invalid / empty), code already applied (yes / no),
and expected result. Include every combination and mark any row the rule does not decide.

Rows the rule does not decide are the most valuable output of the whole exercise. “What happens if the subtotal drops below £50 after the code was accepted?” is a question for the product owner, and it is much cheaper to ask now than after release.

4. Review every suggestion

Now act as the reviewer. Go through the list with four questions:

  1. Is the expected result right? Check each one against the rule. Models sometimes state confidently that 10% off £50.01 is £45.00.
  2. Is it a duplicate? “lowercase code” and “code in mixed case” test the same thing. Keep one.
  3. What is missing? Models tend to miss things that need knowledge of your system: what happens on page refresh, how the discount shows on the receipt, whether the code works in the mobile app’s checkout too.
  4. Is it worth automating? Some ideas are better as a one-off exploratory check than a permanent test.

5. Turn the ideas into tests

Once you have a reviewed list, automation is straightforward, and an assistant can help write the code. Here is what the core cases look like as parametrised pytest tests, assuming the discount logic lives in a function apply_discount(subtotal, code) that raises DiscountError for invalid codes:

# test_discount.py
from decimal import Decimal

import pytest

from shop.discounts import DiscountError, apply_discount


@pytest.mark.parametrize(
    ("subtotal", "code", "expected"),
    [
        (Decimal("50.00"), "SAVE10", Decimal("45.00")),    # exactly at the minimum
        (Decimal("50.01"), "SAVE10", Decimal("45.01")),    # just above, checks rounding
        (Decimal("120.00"), "save10", Decimal("108.00")),  # case-insensitive
        (Decimal("80.00"), " SAVE10 ", Decimal("72.00")),  # surrounding spaces
    ],
)
def test_valid_code(subtotal, code, expected):
    assert apply_discount(subtotal, code) == expected


@pytest.mark.parametrize(
    ("subtotal", "code", "message"),
    [
        (Decimal("49.99"), "SAVE10", "minimum spend"),  # just below the minimum
        (Decimal("80.00"), "SAVE1O", "unknown code"),   # letter O instead of zero
        (Decimal("80.00"), "", "unknown code"),         # empty input
    ],
)
def test_rejected(subtotal, code, message):
    with pytest.raises(DiscountError, match=message):
        apply_discount(subtotal, code)

Two details are worth noticing. Money uses Decimal, not floats, so 50.01 * 0.9 rounds predictably. And the “surrounding spaces” case encodes a decision (trim the input) that the original rule did not make. That decision came from the review in step 4; make sure the product owner agrees before you lock it into a test.

Check that each test can fail: change the minimum in the code to £40 and confirm the boundary tests go red.

6. Ask what your tests would miss

Once the tests exist, turn the model into a critic. Give it the rule and your test file, and ask it to attack the tests rather than the feature:

Here is the rule and my test file. Describe five realistic bugs in an
implementation of this rule that all of these tests would still pass.
For each bug, give the input that would expose it.

This is a lightweight version of mutation testing: instead of a tool changing the code to see whether tests notice, you ask for plausible faults and check whether your suite would catch them. Typical answers include applying the discount to the total including delivery instead of the subtotal, letting a second code stack on top of the first, or comparing the subtotal with > instead of >=. The last one your boundary test at exactly £50.00 already catches; the first two may not be covered at all, and each gap you find is either a new test or a question about the rule.

The same prompt also works as a starting point for an exploratory testing session: take the bug ideas the model suggests and spend twenty minutes trying them by hand in the real checkout.

Pitfalls

Pasting the implementation and asking for tests. You get tests that confirm what the code does, bugs included. Describe intended behaviour.

Trusting expected results. The model’s arithmetic and its reading of the rule both need checking.

Volume over value. Fifty generated cases are not better than twelve good ones. Merge duplicates and drop low-value ideas.

Leaving assumptions unasked. Every [ASSUMPTION] in the output is a question for someone. Ask it.

Sharing what you should not. Use your organisation’s approved assistant for anything that includes internal specifications.

Next steps

Covers

Check your understanding

AI-assisted test design quiz

Describing behaviour, test design techniques, decision tables, reviewing model suggestions and checking your tests can fail.

7 questions · pass mark 70%

Question 1 of 70 answered
  1. Why does the tutorial say to describe the rule rather than paste the implementation?
Back to top