JournalTest cases from requirements: how an AI SDLC writes tests before code
Agentic SDLC

Test cases from requirements: how an AI SDLC writes tests before code

Finny AbrahamFounding Principal Engineer, Orlian
Published
Reading time
8 min
Topic
Agentic SDLC
In short
  • 01A QA agent writes tests from the requirement, its rules and its open questions before any code exists, so the coding agent starts from red.
  • 02Tests written after the code copy its mistakes: models shown buggy code wrote tests that accepted the bug about eight times as often.
  • 03When one agent writes the code and its tests, a misreading passes both. Written first, an open question goes to the product owner.
  • 04Edge cases taken from the code's branches miss what the code never considered, such as a 28-day February, at 100% branch coverage.
  • 05A test that has never failed has never shown it can. Tests written first start red and turn green after a specific change.
  • 06Each test linked to the rule it protects shows which tests a changed rule affects, which is the link auditors ask for.
  • 07In Orlian the QA analyst agent writes traced tests before Build, and a person accepts the test evidence before release.

Test cases from requirements catch the mistakes that test cases from code cannot, because the author of the tests has never seen the code. In an AI SDLC a QA agent writes the tests from the requirement, its rules and its open questions before any code exists and the coding agent then starts from tests that fail. This post follows one requirement through five ways that tests go wrong when they are written after the code, with the usual approach on the left and the requirements-first approach on the right. The wider method is covered in What is an agentic SDLC?

On 4 June 1996 the first Ariane 5 launcher veered off course and broke up about 40 seconds after its flight sequence began. The inquiry board found that an alignment function in the inertial reference system, which served a purpose only before lift-off, stayed active afterwards and was left out of the simulations and it judged the equipment and system tests insufficiently realistic. The function came from an Ariane 4 requirement and Ariane 5 flew a trajectory with higher horizontal velocity. Tests that follow the behaviour the software already has will pass for as long as the flight resembles the last one and the five failures below begin at that gap between what code does and what a requirement demands.

01One requirement, five failures

Every failure below uses the same requirement from a hypothetical subscription product, shown with the rules and the open question that the QA agent works from. The requirement and the code are illustrative.

ItemWording
RequirementA customer who cancels within 14 days of purchase is refunded the unused part of the billing period
RuleThe refund is the price multiplied by unused days, divided by the days in the period
RuleDay 14 counts as inside the window
RuleThe refund returns to the original payment method
Open questionDoes the refund include sales tax? Owner: finance, unanswered

In each failure the left column shows tests written after the code by an author who can read it and the right column shows the requirements-first order. The same input goes into both.

02Failure 1: the test repeats the code's off-by-one

A test written after the code tends to copy the code's mistakes. A 2026 study of 11 language models on real Java bugs shows how much. When the models were shown buggy code, they wrote tests that wrongly accepted the bug about eight times as often (3.84% of tests against 0.46%). They also wrote almost three times fewer tests that caught the bug (2.98% against 8.51%).

The input is a customer who buys on 1 March and cancels on 15 March, which is day 14.

Tests written after the codeTests written from the requirement
What the author readsThe refund function, which checks daysSincePurchase < 14The rule that day 14 counts as inside the window
Test writtenCancelling on day 14 returns no refundCancelling on day 14 returns the refund for the 17 unused days
First runGreenRed: expected a refund, got none
What happens nextThe boundary mistake ships with a test that defends itThe coding agent corrects the comparison before the pull request opens

The right column needed no cleverness, since the rule already said that day 14 counts.

03Failure 2: the author and the code share one reading of the requirement

When one agent writes the code and then its tests, a misreading of the requirement appears in both and the suite goes green. The same 2026 study found a way out that points in the same direction: asking the model to write down the intended behaviour first and prompting from that description instead of the code raised the share of bug-catching tests from 2.98% to 4.50%.

The input is the open question about sales tax, which finance has not yet answered.

Tests written after the codeTests written from the requirement
What the author readsThe requirement and the refund code it has just writtenThe requirement, its rules and the open question, with no code in existence
What it does with the open questionPicks a reading (the refund excludes tax) and writes the code and the test to matchCannot answer it and lists it for the product owner
First runGreen, with a tax assumption that nobody approvedThe tax tests are marked blocked and the other tests run red
What happens nextFinance finds the refunds short after launchThe product owner sees the question before the planning gate is signed
The QA agent writes the tests before any code exists
Usual order: tests written after the code
  1. Requirement
  2. Coding agent writes the codecode comes first
  3. Same agent writes the testscode is in view
  4. Tests agree with the code
Requirements first: tests written before the code
  1. Requirement, rules, questions
  2. QA agent writes the testsno code exists yet
  3. Planning gate: owner signs
  4. Coding agent starts from redtests already fail
Figure 1 · tests after the code against tests before it, two lanes

In the usual order one agent holds the code while it writes the tests. In the requirements-first order the QA agent writes against the requirement alone and the coding agent inherits tests that already fail.

04Failure 3: the edge cases come from the code's branches

A test author who reads the code looks for paths to cover, so a case that the code never considered never gets a test. The branch coverage report then reads 100% because the code has no branch for it.

The input is a customer on a 30.00 plan who buys on 1 February, a period of 28 days and cancels on 15 February.

Tests written after the codeTests written from the requirement
Where the cases come fromThe two branches of the refund function: inside the window and outside itThe rules: the window edges at days 13, 14 and 15, period lengths of 28, 30 and 31 days and the payment method
Month length in the testsA 30-day month in every caseEach period length gets its own case
Coverage report100% of branchesEvery rule maps to at least one test
First run on the February inputGreen, because February was never triedRed: expected 15.00, got 14.00

The code divides by a fixed 30 and the rule says to divide by the days in the period. Only the second author was reading the rule.

05Failure 4: a test that has never failed has never shown it can

Tests written after the code usually pass on the first run, because the author checks them against code that already exists and adjusts them until they pass. A test that has never failed has never been shown to catch anything, since it would pass whether the code was right or wrong. Tests written first start red: they fail because the feature does not exist yet and they turn green only when the coding agent makes the right change.

The input is the first run of the suite for the refund requirement.

Tests written after the codeTests written from the requirement
What the first run showsAll six tests pass, so nobody has seen any of them failFive tests fail because the code does not exist yet and one is blocked by the open tax question
What a pass meansOnly that the test matches the code, even when the code is wrongThe test failed first and passed after a specific change, so it can catch that fault
Evidence keptA green checkThe failing run, the fixing change and the passing run, linked to the requirement
Tests fail for a named reason first and pass after each fix
Run 1 · before any code
  • failday 13 refunds
  • failday 14 refunds
  • failday 15 no refund
  • fail28-day period
  • failoriginal card
  • blockedtax question
5 failed · 0 passed
Run 2 · first draft
  • passday 13 refunds
  • failday 14 refunds
  • passday 15 no refund
  • fail28-day period
  • passoriginal card
  • blockedtax question
2 failed · 3 passed
Run 3 · after both fixes
  • passday 13 refunds
  • passday 14 refunds
  • passday 15 no refund
  • pass28-day period
  • passoriginal card
  • blockedtax question
0 failed · 5 passed

Illustrative output for the refund requirement; the blocked test waits for finance to answer the tax question

Figure 2 · three runs of the refund suite, red to green

Run 2 is where the boundary and the divisor from failures 1 and 3 surface and the coding agent fixes both before opening the pull request.

06Failure 5: the tests lose their link to the requirement

When tests come from the code nothing records which requirement each one protects, so a change to the requirement has to be traced by hand. Auditors ask for exactly that link and the same gap leaves old tests in place that still defend the previous rule.

The input is a product owner who widens the refund window from 14 days to 30.

Tests written after the codeTests written from the requirement
Where the change startsIn the code, with the tests patched until the build is greenAt the window rule, which the product owner changes
Which tests are affectedWhichever ones a search for the number 14 turns upThe tests linked to the window rule, listed from the link
The old test for day 15Edited to make the build passRewritten from the new rule before the code changes
Record for an auditA test file with no requirement attachedEach test linked to the rule it protects, with the change history
One changed rule flags exactly the tests linked to it
Requirement and rules
Tests
Window rulechanged to 30 days
Day 13 refunds
Day 14 refunds
Day 15 gets no refund
Refund divides by the days in the period
28-day period refunds half
Refund returns to the original card
Refund lands on the original card
Open question: sales tax, unanswered
Tax refund (blocked)

Blue marks the changed rule and the three tests linked to it.

The dashed link joins the open question to its blocked test.

Figure 3 · rules linked to tests, with one rule changed

The link runs from each test to the rule it protects, so the change to the window rule lists its three tests and leaves the other three alone.

07Where Orlian fits

Orlian builds this order into the AI SDLC. The QA analyst agent sits in the AI requirements, specs and test cases wing and writes the tests before the code exists, with each test traced to the requirement it protects. The product owner approves the requirements at the planning gate before any code is written and on a live project that gate held because two critical open items had no owner.

In Build the Dev agent starts from the failing tests and its stage policy keeps test writing with a separate agent. When a review comment asked it to add tests it quoted both rules, paused the ticket and asked an engineer. In Verify the AI test automation agents run the traced tests against staging and file every failure to Build with its requirement attached and a person accepts the evidence before release.

Flight 501 is the large version of the refund example: software that did what its code said, tested against the last flight. A test written from a requirement for the flight in hand asks what that flight needs, whatever the code already does.

Filed underAgentic SDLC
Written by

Finny Abraham

Founding Principal Engineer, Orlian. Finny works with engineering and quality teams on writing tests from requirements before any code exists and tracing each test to the rule it protects.

The Journal, by email

Get the next field note in your inbox.

We write when we have something worth reading: the method behind the platform, and what we learn delivering with it.

You're on the thread.

Thank you for your interest. The next field note will land in your inbox the moment it's written. We'll send updates, never noise.

That didn't go through. Check the email address and try again, or write to us at hello@orlian.ai.

One email per field note. No noise, and you can unsubscribe anytime.