2.2 Applying prompt engineering techniques to software testing tasks
Now that you know how to structure a prompt (the "how"), let's look at the "when" and the "why". For the MagicFridge QA team, AI is a production tool that intervenes at every stage of the test process, from requirements analysis to final reporting.
2.2.1 Test analysis with generative AI
Analysis is often the most intellectual stage: understanding what needs to be tested. AI excels here at detecting gaps.
The syllabus lists 5 major analytical tasks that generative AI can support:
- Identify potential defects in the test basis: spot ambiguities, inconsistencies, or omissions in User Stories.
- Generate test conditions: break down a requirement into testable statements.
- Prioritize test conditions (risk-based): suggest a risk level (impact/likelihood) to focus the effort.
- Support coverage analysis: verify that every requirement is mapped to at least one test condition (traceability matrix).
- Suggest test techniques: recommend the most suitable approach (e.g., boundary value analysis, equivalence partitioning).
Red thread: MagicFridge
Context: the Product Owner provides a User Story: "The user can modify the quantity of an ingredient in the cart."
The tester sends this text to the AI with the instruction: "Act as a test analyst. Analyze this requirement, identify gaps, generate test conditions, propose prioritization by risk, and suggest test techniques."
The AI response (The 5 tasks in action):
- Defect identified: "The requirement does not specify what happens if the quantity is 0. Should the item be removed?"
- Conditions generated:
- Modify quantity > 0 (Valid).
- Modify quantity = 99 (Max).
- Modify quantity = -1 (Invalid).
- Prioritization: "High Risk for negative values (risk of order corruption). High Priority."
- Coverage: "Alert: No business rules provided for stock management related to the cart. Coverage gap detected."
- Suggested technique: "Use boundary value analysis to test the 0, 1, and 99 thresholds."
2.2.2 Test design and implementation
Once we know what to test, we need to create test cases and data. This is where the techniques seen in 2.1 (chain-of-thought, few-shot) become crucial.
AI enables us to:
1. Generate test cases (Gherkin, tables).
2. Synthesize test data (anonymization, generation of fake profiles).
3. Schedule execution (prioritizing tests).
Red thread: MagicFridge
Objective: create BDD tests (Gherkin) for the "Add ingredient" feature.
Technique used: few-shot prompting (learning by example) The tester gives the AI two examples of perfect Gherkin scenarios (syntax, style). Then she asks: "Generate the scenario for an expired ingredient following this model."
Result: The AI produces a perfectly formatted Given-When-Then scenario, ready to be copied into the automation tool.
2.2.3 Automated regression testing
This is the area where time savings are most spectacular. AI does not replace the automation engineer, but becomes his "coding partner" (Pair Programmer).
It helps to:
1. Generate scripts (Selenium, Cypress, Playwright) from textual descriptions.
2. Repair tests (self-healing): if a CSS selector changes, the AI can analyze the HTML code and propose the fix.
3. Analyze impact: identify which tests to re-run after a code modification.
Red thread: MagicFridge
The problem: developers renamed the button ID #btn-add to #button-add-item. All automated tests are failing.
AI intervention: the tester pastes the error log and the new HTML code into the prompt.
Instruction: "Analyze this Selenium error and propose the fix."
Response: "The element is no longer found. Replace driver.find_element(By.ID, "btn-add") with driver.find_element(By.ID, "button-add-item")."
2.2.4 Test monitoring and control
When you have 5,000 tests running every night, analyzing results is a nightmare. AI can "read" these mountains of data to extract meaning.
It allows us to summarize test reports, visualize metrics, and detect anomalies in logs that the human eye might have missed.
Red thread: MagicFridge
Monday morning, 45 tests failed. Instead of opening them one by one, the Test Lead asks the AI: "Analyze these 45 error logs and group them by root cause."
AI insight: "Out of 45 failures, 42 are caused by a Payment API Timeout (Error 504). The other 3 are real interface bugs."
The time saving is immediate: she knows she needs to call the Back-end developers, not the Front-end developers.
2.2.5 Choosing the right prompting technique
The syllabus insists: not all techniques are equal for all tasks. Here is the GenAI tester's strategic guide.
| Test task | Recommended technique | Why? |
|---|---|---|
| Complex analysis (e.g., ambiguous User Story) | Prompt Chaining | Breaking down the problem prevents the AI from getting lost or hallucinating. We validate step-by-step. |
| Repetitive generation (e.g., Gherkin test case) | Few-shot prompting | The example (the "shot") forces the AI to respect a strict format. |
| Exploration / Ideation (e.g., finding edge cases) | Meta-prompting | We ask the AI to think about the best way to test, to think outside the box. |
Syllabus point (key takeaways)
- Analysis: AI helps clarify the test basis and identify defects early.
- Design: It generates test cases, oracles, and synthetic data.
- Automation: It writes and repairs (self-healing) scripts.
- Management: It synthesizes logs and assists decision-making.
- Strategy: You must adapt the prompt technique (chaining vs few-shot) to the nature of the task.