Preface
With the widespread application of large AI models in software testing, prompt engineering has become a key skill for test engineers to improve efficiency. Through precise prompt design, we can quickly generate test cases, optimize test scenarios, generate automation scripts, and even achieve intelligent test coverage.
So how can we use large models more effectively and have them help us reach the desired results more efficiently? Good prompts let us achieve twice the result with half the effort. The following summarizes, for test engineers, how to write a good prompt framework.
Breaking Down Complex Requirements and Describing Problems Precisely
The effectiveness of large AI models depends heavily on the clarity of the input prompt, that is, on minimizing ambiguity as much as possible. So when entering a prompt, you should break complex tasks down into concrete requirements as much as possible, for example:
- Scenario-based descriptions: specify the test objective (e.g., “generate boundary-value test cases for the login function”) rather than a vague instruction (e.g., “help me write test cases”).
- Constraints: add format requirements (e.g., “output in table form”), priorities (e.g., “include only high-risk scenarios”), or technical limitations (e.g., “no third-party APIs involved”).
- Example guidance: provide sample data or templates to help the model understand the expected output structure.
Using a Structured Framework to Improve Output Stability
By defining a structured prompt framework, you can constrain model behavior and reduce random interference:
- Role setting: specify a professional role for the model to play (e.g., “you are a senior testing expert skilled at designing high-coverage test scenarios”).
- Step-by-step instructions: break a complex task into multiple steps (e.g., “Step 1: analyze the requirements document; Step 2: identify critical paths; Step 3: generate cases”).
- Chain-of-Thought: although many models now offer deep-thinking capabilities, guiding the model’s analysis through prompts can simplify the direction of its reasoning. For example, “first analyze the user operation flow, then focus on generating test cases for exception scenarios”.
Progressive Iterative Optimization and Continuous Prompt Improvement
Large models usually retain conversation context; for the result of each round of feedback, you should keep correcting and gradually move toward the best output.
- Feedback correction: promptly point out errors in the model’s output (e.g., “case 2 does not cover the timeout scenario, please add it”) and ask for regeneration.
- Parameter tuning: control output length (e.g., “describe in 50 characters or less”) and the Temperature coefficient to balance the model’s creativity and accuracy.
- Cross-comparison: there are many open large models today with varying capabilities, and their analysis results can differ considerably. Judge comprehensively and extract the best result.
Some common correction scenarios:
| Problem | Cause | Improvement |
|---|---|---|
| Output too broad | Vague requirement description | Add specific scenarios, format, and priority constraints |
| Repeated or redundant results | Output scope not clearly limited | Exclude unwanted scenarios (e.g., specify “output only uncovered boundary-value scenarios”) |
| Incorrect technical terminology | Model lacks domain knowledge | Provide a glossary or specify a role (e.g., “financial systems testing expert”) |
Case Study
Based on the principles above, taking the shopping flow of the website https://www.saucedemo.com that we want to test as an example, to use a large model to help us generate a series of test cases, the prompt framework can be set up as follows:
| |
The prompt above maps fairly well to the relevant prompt framework principles:
- Clear role: “Assume you are an experienced software test engineer…”
- Clear task: “Generate detailed, high-priority positive and negative test cases for the following user scenarios. Focus on the complete flow from product selection to a successful order”
- Sufficient contextual information: the URL under test, user information, case focus, and tax rate assumptions
- Specified output format: “Output the test cases as a Markdown table containing the following columns:
Case ID,Test Description,Preconditions,Test Steps,Expected Result,Priority.” - Clear specific requirements and constraints: the specific requirements for cases and output,
- Guiding the direction of thinking: using problem_user to generate exception cases
Finally, with such a prompt, through Deepseek we obtain the following set of generated test cases:
High-Priority Core Shopping Flow Test Cases
| Case ID | Test Description | Preconditions | Test Steps | Expected Result | Priority |
|---|---|---|---|---|---|
| Positive Test Cases | |||||
| TC_SAUCE_SHOP_001 | Standard user logs in successfully and enters the product list page | None | 1. Visit https://www.saucedemo.com/2. Enter username standard_user and password secret_sauce3. Click the login button | Login succeeds, redirecting to the product list page (Inventory Page) | High |
| TC_SAUCE_SHOP_002 | Add two different products to the cart and verify the quantity | User logged in | 1. On the product list page, select two different products and click the “Add to Cart” button for each 2. Check that the cart icon shows a quantity of 2 | The cart icon quantity updates to 2, and both products appear on the cart page | High |
| TC_SAUCE_SHOP_003 | Verify product information and total price (excluding tax) on the cart page | User has added two products to the cart | 1. Click the cart icon to enter the cart page 2. Check the product name, quantity, and unit price 3. Calculate the total price (product 1 price + product 2 price) | Product information is correct, and the total price shows the sum of the two products | High |
| TC_SAUCE_SHOP_004 | Complete valid checkout information and verify the tax-inclusive total | User has entered the checkout information page | 1. On the checkout information page, enter a valid first name, last name, and postal code (e.g., John/Doe/12345) 2. Click the “Continue” button 3. On the overview page, verify the total price (total = product total * 1.08) | Redirected to the checkout overview page, total includes 8% tax and is calculated correctly | High |
| TC_SAUCE_SHOP_005 | Complete the purchase and verify the order success message | User has entered the checkout overview page | 1. Click the “Finish” button | Displays the “THANK YOU FOR YOUR ORDER” success message and returns to the product list page | High |
| Negative Test Cases | |||||
| TC_SAUCE_SHOP_006 | Submit the form with an empty name on the checkout information page | User has entered the checkout information page | 1. Leave the name field blank and enter a valid postal code (e.g., 12345) 2. Click the “Continue” button | Shows “First Name is required” and blocks navigation | High |
| TC_SAUCE_SHOP_007 | Invalid postal code format on the checkout information page (e.g., non-numeric) | User has entered the checkout information page | 1. Enter a valid first name and last name, with postal code “ABC12” 2. Click the “Continue” button | Shows “Postal Code is invalid” and blocks navigation | High |
| TC_SAUCE_SHOP_008 | Attempt to check out with an empty cart | User logged in with an empty cart | 1. Click the cart icon to enter the cart page 2. Click the “Checkout” button | Shows “Cart is empty” or blocks navigation to the checkout page | High |
| Problem User Test Cases | |||||
| TC_SAUCE_SHOP_009 | Problem User shows abnormal product images when adding products | Problem User logged in | 1. Browse the product list page 2. Check whether product images load correctly (e.g., misplaced or failing to display) | Product images display abnormally (e.g., blank or wrong images) | Medium |
| TC_SAUCE_SHOP_010 | Problem User total price calculation error at checkout | Problem User has added products to the cart | 1. Complete the checkout flow up to the overview page 2. Verify whether the total equals product total * 1.08 | Total price calculation error (e.g., tax not included or deviated value) | Medium |
Supplementary Notes
- Priority assignment: core flows (login, adding products, checkout) and key exception scenarios (empty fields, invalid data) are set to high priority.
- Problem User: used to verify specific abnormal behaviors (such as UI rendering errors or logic flaws).
- Actual Result/Status: to be filled in based on actual observations during execution (such as “Pass”, “Fail”, or “Blocked”).
- Tax calculation: assuming the product total is
$X, the tax-inclusive total should beX * 1.08, rounded to two decimal places (e.g.,$21.99 * 1.08 = $23.75).