A Shift Left Testing Example: One Requirement, Tested Before the Code
Follow one order-quantity rule from the requirements document to tests that exist before the code does, and see what shifting left changes for QA, how it differs from TDD, and what it costs.
This is lesson 8.1 of AI and Shift-Left Testing Strategy. It follows one requirement through a shift-left workflow; for the definition, benefits and maturity levels, start with what is shift-left testing.
A shift left testing example in one sentence
Here is a shift left testing example you can check yourself: take one rule from the sandbox store's requirements, "order quantity is an optional whole number of at least 1, and defaults to 1", and write its tests while the rule is still being discussed, before anyone writes the code. The tests then wait for the code, and the first build that breaks the rule fails on the spot. Nothing about the check changes; only the moment you first run it does.
The shift-left testing pillar page moves a contract check through four pipeline stages. This lesson starts one step earlier, with a requirement.
The requirement, as written
The sandbox store's requirements document states it twice. Functional requirement FR-004 says POST /api/v1/orders returns 201 with the order, and that quantity defaults to 1. Business rule O-01 adds the detail:
RULE O-01 quantity — optional whole number of at least 1. Default 1. Invalid → 400: 0, -1, 1.5, 2.5.
On a traditional timeline, this rule is coded first and tested later. On a shifted-left one, QA reads it in refinement and asks the questions that become tests.
Step 1: test the requirement before the code
A requirement is testable when every input has an expected outcome. Write the examples down and see which ones the document answers:
| Input | Expected | Answered by |
|---|---|---|
quantity: 1 | 201, quantity 1 | O-01 |
quantity: 3 | 201, quantity 3 | O-01 |
| quantity left out | 201, quantity 1 | O-01 (default) |
quantity: 0 | 400 VALIDATION_ERROR | O-01 |
quantity: -1 | 400 | O-01 |
quantity: 1.5 | 400 | O-01 |
quantity: 1000000 | ? | Not stated |
quantity: "2" | ? | Not stated |
Two rows have no answer. Is there an upper limit? Is a numeric string accepted or rejected? That is the cheapest defect you will ever find: a gap in a sentence, fixed by editing the sentence. Found after release, the same gap is a production incident ("a customer ordered a million units") or a compatibility promise you can no longer take back.
Step 2: make the examples executable
The table becomes tests before the endpoint exists. They need only the contract: the path, the request body, the expected status and fields. The spec says quantity is an integer with minimum: 1 and default: 1, so the positive, negative and boundary cases can be written, or generated, from it plus the rule.
Against the real sandbox, which already implements the rule, you can see both sides:
/api/v1/orderscurl -X POST 'https://demo.totalshiftleft.ai/api/v1/orders' \
-H 'Content-Type: application/json' \
-d '{"quantity":0}'/api/v1/orderscurl -X POST 'https://demo.totalshiftleft.ai/api/v1/orders' \
-H 'Content-Type: application/json' \
-d '{"quantity":2}'The first returns 400 with details[0].field set to quantity; the second returns 201 with status: "pending". In a real project, at this point the endpoint would not exist yet: the tests run against a mock server built from the spec, or simply wait in the suite until the first build.
Step 3: let the tests gate the first commit
When the developer opens the pull request that adds the endpoint, the suite runs on it. If the implementation accepts quantity: 0, the build fails before review, with a test whose name points back to O-01. Nobody needs to remember the rule; the suite does.
Three things made this work, and none of them is a tool:
- The rule was written down with examples.
- QA took part before the code, not after it.
- The tests existed before the change that they judge.
Shift left testing in QA: what changes for testers
Shifting left moves QA's centre of gravity, not QA's existence.
- Refinement becomes test design. Testers ask "what should happen when…" for each acceptance criterion and record the answers as examples.
- Testers own the oracle. The expected outcomes come from requirements and the spec, not from whatever the code happens to return.
- Developers run the tests first. The suite runs on their branch, so most failures are seen by the person who caused them, minutes later.
- Exploratory and release testing stay. They stop being the first chance to find a defect and become a check on what the earlier stages missed.
The hard part is usually the requirements, not the testing: unclear rules are one of the six adoption problems covered in shift-left testing challenges.
Shift left testing vs TDD
They are related, and often confused.
| TDD | Shift-left testing | |
|---|---|---|
| What it is | A coding practice | A lifecycle strategy |
| Who drives it | The developer | The whole team, often led by QA |
| Level | Unit tests | Requirements, contracts, API, integration, non-functional |
| Starts from | A small piece of behaviour the developer is about to write | A requirement, a spec or a risk |
| Example here | A unit test for a validateQuantity() function | The eight examples above, as API tests, before the endpoint exists |
TDD is one way to shift left at the unit level. The closer relatives of this example are acceptance-test-driven development and behaviour-driven development, which also start from examples agreed before coding.
Shift left testing pros and cons
| Pros | Cons |
|---|---|
| A gap in a requirement is fixed by editing a sentence | Refinement takes longer, especially at first |
| Most failures are seen by the developer who caused them | Tests written against moving requirements churn |
| The suite records the rules, so knowledge doesn't live in one tester's head | It depends on written requirements or a spec |
| Release testing shrinks to what only release testing can see | It cannot see production-only problems: configuration, real traffic, real data |
The last con is why shift-left is never the whole strategy. Lesson 8.3 covers what stays on the right.
Common mistakes
- Writing tests from the implementation. If the expected result is "whatever it returned", the test can't find a defect.
- Skipping the unanswered rows. The
"2"and1000000cases are the valuable ones; leaving them out hides the gap. - Shifting only the work, not the decision. If QA writes early tests but nothing fails a build, the tests are documentation.
In Shift-Left API: requirements to tests before a run
Shift-Left API reads the requirements document and the spec together, so the rule above becomes tests before anything has been executed. Lesson 9.2 walks through the screens in full; here is the short version.
- Set up an AI provider first: reading prose documents uses AI, with your own key or, on Trial and Enterprise, a self-hosted model.
- In a project built from
https://demo.totalshiftleft.ai/openapi/rest.json, open Requirements, click Choose requirement files, and upload the store's requirements document. - Click Review all requirements. Rules the AI read from prose wait for your approval; rules read from structured sources such as the spec are approved automatically unless they conflict, so the quantity rule may already be approved. Approve what is waiting.
- Open Orders → Create a new order and click Generate tests. The tests are planned from the spec and the approved requirements; generating runs nothing against the API.
- Open Requirements → Traceability. The quantity requirement is listed with its source in the document and its linked tests, and the Tests column says they have not run.
That last screen is the shift-left moment in one row: a requirement with tests, and no code run yet.
Try it yourself
In the free edition, upload the store's requirements to a project built from the sandbox spec, approve the requirements, generate tests for Create a new order, and open Traceability. Find the quantity rule: how many tests are linked to it, and what does the Tests column say about them?
Recap
- A shift left testing example starts with a requirement, not a tool: write the examples, find the unanswered rows, and turn them into tests before the code.
- Shift left testing in QA moves testers into refinement and test design; exploratory and release testing remain as a later check.
- Shift left testing vs TDD: TDD is a unit-level coding practice and one way to shift left; the strategy covers requirements, contracts and APIs too.
Next, in lesson 8.2, you turn this one example into a team practice: rituals in agile, gates in the pipeline.
Try it: In the free edition, with an AI provider set up, upload the sandbox store's requirements document to a project built from its spec, approve the extracted requirements, generate tests for Create a new order, then open Requirements → Traceability.
- Use this sandbox asset
- https://demo.totalshiftleft.ai/requirements/store.txt
- You got it right when
- The order-quantity requirement is listed with the document it came from and a count of linked tests marked "not run": the rule has tests before anything has been executed.
Frequently asked questions
What does shift left testing in QA change for testers?+
Testers move from running checks at the end to shaping them at the start. They review requirements for testability, turn each acceptance criterion into concrete examples, and own the test design that developers' code must then pass. Exploratory testing and release checks stay; they just stop being the first place a defect can be found.
What is the difference in shift left testing vs TDD?+
TDD is a developer practice at unit level: write a failing unit test, then the code that makes it pass. Shift-left testing is a strategy for the whole lifecycle that moves every kind of check earlier, from requirement review to API contract tests in the pull request. TDD is one way to shift left, not the whole of it.
What are the main shift left testing pros and cons?+
The pros are cheaper fixes, ambiguous requirements found before anyone codes them, and fast feedback on every change. The cons are time spent up front in refinement, tests that churn while requirements are still moving, and a dependence on written requirements or a spec. It also cannot see problems that only appear in production, which is why teams keep checks on the right as well.
Related lessons
Shift-left testing is a set of decisions, not a tool. Map every check to the earliest stage it can run, change three agile rituals, put gates in the pipeline, and measure where defects are now found.
A spec says what's valid, not what the business needs. Upload a requirements document to Shift-Left API, review what it extracts, and generate tests that trace back to each rule.
Shift left and shift right aren't rival philosophies. Place each risk where it can first be seen, connect the two with an incident-to-test loop, and keep a scheduled smoke pack as the bridge.
Read more on the blog
Shift left testing delivers proven benefits, but adoption is rarely without friction. Cultural resistance, automation skill gaps, test environment complexity, unclear requirements, tool sprawl, and ROI measurement challenges are the obstacles teams most commonly face. This guide pairs each challenge with a concrete, actionable solution.
Choosing the right shift left testing tools can mean the difference between catching bugs in development and paying ten times more to fix them in production. This comprehensive guide covers the top tools DevOps teams are using in 2026 to embed quality earlier in every sprint, with Shift-Left API leading the way for API test automation.