Optivem Journal

Optivem Journal

Spec-Driven Development

Acceptance Criteria for the Core Use Case in Legacy Code with AI

Turn the use case narrative and the business rules into Given/When/Then with real values, with the AI prompt for each step (Acceptance Testing in Legacy Code with AI - Phase 1).

Valentina Jemuović's avatar
Valentina Jemuović
Nov 27, 2026
∙ Paid

🔒 Hello, this is Valentina with a premium issue of the Optivem Journal. I help Engineering Leaders & Senior Software Developers cover legacy code with acceptance tests, using AI. This article is part of the Acceptance Testing in Legacy Code with AI series. To get these articles in your inbox every week, subscribe.

We have a legacy system with no acceptance tests, and we want to cover it using AI. In Core Use Case Narrative & Business Rules in Legacy Code with AI, we wrote down what Place Order does: the use case narrative and the business rules. Now we write acceptance criteria based on them, the interim step on the way to acceptance tests.

Why not go straight to acceptance tests? Tests are code, and code is more expensive to change than plain text. The first version of the acceptance criteria will need fixes, mostly to the business language: how we word a Given, a When or a Then. In plain text, rewording a step is a quick edit. In tests, it means renaming DSL methods across the test code.

The biggest risk isn’t correctness: the acceptance tests will catch that. It’s missing what matters most. So we’re not aiming for exhaustive, just for what the use case narrative and the business rules identified.


Work with me in 2027

I set up the acceptance test architecture and work hands-on with your teams to cover your system with acceptance tests, until your teams write them on their own. Every feature gets verified automatically before release, and regression bugs stop reaching production. If you want to work together in 2027, book a call.


What the Use Case Narrative and the Business Rules Don’t Have

What we have so far for Place Order, the main success scenario of the use case narrative:

1. The customer submits an order for a product: its SKU and a quantity.
2. The system validates with the Clock that orders are being accepted at this time (BR-9).
3. The system gets the product and its unit price from the ERP.
4. The system gets the tax rate for the customer's country from Tax.
5. The system calculates the total price (BR-1 to BR-7).
6. The system stores the order with status PLACED.
7. The system shows the customer a success message and the order number.

Its extensions are either alternatives, which still end with the order placed, like 1a “The customer submits a coupon code”, or exceptions, which don’t, like 1b “The coupon can’t be used”.

The business rules:

- BR-1. Base price = unit price x quantity.
- BR-2. When the ERP has an active promotion, promoted price = base price x promotion factor. Otherwise, promoted price = base price.
- BR-3. Discount = promoted price x the coupon's discount rate. With no coupon, the discount is 0.
- BR-4. Subtotal = promoted price - discount.
- BR-5. Tax = subtotal x the tax rate for the country.
- BR-6. Total price = subtotal + tax.
- BR-7. Amounts are rounded to 2 decimal places and rates to 4, half up, once, at the end.
- BR-8. A coupon can be used when it exists, the time is between its valid-from and valid-to, and it hasn't reached its usage limit.
- BR-9. Orders aren't accepted between 23:59 and 00:00 UTC on December 31st.

Both are general: no inputs, no outputs, so they aren’t testable. Step 5 of the main success scenario says “The system calculates the total price”. Is that working? Two people read it and expect two different totals. To find out, they’d have to run the system or read the code.

Acceptance criteria express them in concrete inputs and outputs. For BR-1: unit price 20.00 and quantity 5 give base price 100.00. Not “a valid unit price”: “valid” is open to interpretation, 20.00 isn’t.

Each scenario checks one behaviour, so when it fails, its name tells you what broke. The acceptance criteria for the flows (the main success scenario, the alternatives and the exceptions) check the paths through the use case. The acceptance criteria for the business rules check the values and the edges.

The coupon shows up in the use case narrative and in the business rules, but as two different things:

  • BR-8, the business rule: when a coupon can be used. Between its valid-from and its valid-to, and below its usage limit.

  • 1b, the extension: what happens when it can’t be used. The order fails, and the customer is told why.

So the exception scenario checks the message, with a coupon that expired a month ago, and the business rule scenarios check the exact second the coupon expires. If the message changes, only the first fails. If the coupon expires a second too early, only the second does.

The steps:

  1. Write acceptance criteria for the main success scenario

  2. Write acceptance criteria for the alternative scenarios

  3. Write acceptance criteria for the exception scenarios

  4. Write acceptance criteria for the business rules

Write acceptance criteria for every use case in the dependency tree, not just Place Order. We’ll need them later for the acceptance tests: Place Order’s acceptance tests run Publish Coupon and Create Customer in their Given, so those use cases need acceptance criteria too. The steps run once per use case, dependencies first: Create Admin, Create Customer and Publish Coupon, then Place Order and View Order, which depend on each other: Place Order’s Then runs View Order, and View Order’s Given runs Place Order. The prompts work for any of them: replace <use case> with its name, like Place Order (UC-001), and <use-case> with its file name, like UC-001-place-order. The examples show Place Order, in an online shop.

1. Write Acceptance Criteria for the Main Success Scenario

The simplest order that gets placed: nothing optional, so no coupon, and no prices, since the prices are business rules, with their own acceptance criteria. AI works from the use case narrative, the business rules and the source code.

AI prompt: Write the acceptance criteria for the main success scenario of <use case>, in Given/When/Then, in docs/acceptance-criteria/<use-case>.md.

  1. Read the use case narrative in docs/use-cases/<use-case>.md, the business rules in docs/business-rules/<use-case>.md, and the source code.

  2. Leave out everything optional, and leave out the calculations: they are business rules.

  3. Write one scenario per behaviour the user sees.

  4. In Given, name only what the result depends on, as a business fact. Behind each Given is either a use case from the dependencies in docs/use-cases/README.md, or an answer from an external system. Name the external system only when its own behaviour is the point, like it being unavailable.

  5. Tag each scenario with @narrative-main.

Don’t mention screens, buttons, the database or the API. Stay at the user’s level, like the use case narrative. Describe what the system does today, not what it should do.

For Place Order (UC-001), the output from AI may look like this, in docs/acceptance-criteria/UC-001-place-order.md:

Feature: Place Order

@narrative-main
Scenario: Order status is PLACED
  When the customer places an order
  Then the order is placed successfully
  And the order status is PLACED

@narrative-main
Scenario: Order number starts with ORD-
  When the customer places an order
  Then the order is placed successfully
  And the order number starts with "ORD-"

Two behaviours, two scenarios: if the status is wrong, only the first fails; if the prefix is wrong, only the second. In both, “the order is placed successfully” is a guard: no order, no status or order number to check.

Neither has a Given, because the result doesn’t depend on the product, the customer or the time. The test fills in defaults.

2. Write Acceptance Criteria for the Alternative Scenarios

An alternative still ends with the order placed. In Place Order, that’s extension 1a: an order with a coupon.

AI prompt: Add the acceptance criteria for the alternative scenarios of <use case> to docs/acceptance-criteria/<use-case>.md.

  1. For each extension in the use case narrative that still ends with the result of the use case, write one scenario per behaviour.

  2. Check what the alternative changes in the flow. Leave out the calculations: they are business rules.

  3. Tag each scenario with its extension, like @narrative-1a.

For Place Order, the output from AI may look like this:

@narrative-1a
Scenario: Customer places an order with a coupon
  Given a coupon "SUMMER"
  When the customer places an order with coupon "SUMMER"
  Then the order is placed successfully
  And the order shows applied coupon "SUMMER"

The discount is BR-3, so it goes with the business rules.

User's avatar

Continue reading this post for free, courtesy of Valentina Jemuović.

Or purchase a paid subscription.
© 2026 Valentina Jemuović, Optivem · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for writing, podcasting, and media founders.