A Prompt-Writing Framework for Test Engineers to Use Large AI Models Effectively

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:

  1. 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”).
  2. 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”).
  3. 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:

ProblemCauseImprovement
Output too broadVague requirement descriptionAdd specific scenarios, format, and priority constraints
Repeated or redundant resultsOutput scope not clearly limitedExclude unwanted scenarios (e.g., specify “output only uncovered boundary-value scenarios”)
Incorrect technical terminologyModel lacks domain knowledgeProvide 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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Assume you are an experienced software test engineer responsible for end-to-end functional testing of the core shopping flow of the e-commerce website https://www.saucedemo.com/


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.


Site under test: https://www.saucedemo.com/ 

Test user credentials:

• Standard User: standard_user / secret_sauce
• Problem User: problem_user / secret_sauce (used to observe specific erroneous behavior)


Core shopping flow steps:

1. User login
2. Browse the product list (Inventory Page)
3. Select at least two different products and add them to the cart
4. View the cart (Cart Page)
5. On the cart page, verify product information (name, quantity, price) and the total price
6. Enter the checkout information page (Checkout: Your Information)
7. Fill in valid checkout information (first name, last name, postal code)
8. Enter the checkout overview page (Checkout: Overview)
9. On the overview page, verify product information and the total price (including tax)
10. Complete the purchase (Checkout: Complete!)
11. Verify the order success message


Test case requirements:

• Positive test cases: cover every step of a successful shopping flow using the standard user, ensuring the functionality works as expected.
• Negative test cases:
	• Attempt to enter invalid data on the checkout information page (for example, empty or malformed first name, last name, or postal code).
    • Attempt to check out when the cart is empty.
    • (Optional) Log in with problem_user to observe and record any abnormal behavior in the shopping flow, especially product images, adding to cart, or the checkout step.

Output requirements:
• Each test case should include: Case ID (TC_SAUCE_SHOP_XXX), Test Description, Preconditions (e.g., logged in with products added), Test Steps (clear and executable), Expected Result, Actual Result (left blank), Status (left blank), and Priority (High/Medium/Low).
• Prioritize generating high-priority test cases.



Output format:  Output the test cases as a Markdown table containing the following columns: Case ID, Test Description, Preconditions, Test Steps, Expected Result, Priority.


Constraints:

• Assume a tax rate of 8%.
• Focus on the correctness of UI element interactions and page navigation.
• If you are unsure about the ID or Class of certain elements, use a generic description, for example "click the Add to Cart button" or "enter the name field".

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 IDTest DescriptionPreconditionsTest StepsExpected ResultPriority
Positive Test Cases
TC_SAUCE_SHOP_001Standard user logs in successfully and enters the product list pageNone1. Visit https://www.saucedemo.com/
2. Enter username standard_user and password secret_sauce
3. Click the login button
Login succeeds, redirecting to the product list page (Inventory Page)High
TC_SAUCE_SHOP_002Add two different products to the cart and verify the quantityUser logged in1. 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 pageHigh
TC_SAUCE_SHOP_003Verify product information and total price (excluding tax) on the cart pageUser has added two products to the cart1. 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 productsHigh
TC_SAUCE_SHOP_004Complete valid checkout information and verify the tax-inclusive totalUser has entered the checkout information page1. 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 correctlyHigh
TC_SAUCE_SHOP_005Complete the purchase and verify the order success messageUser has entered the checkout overview page1. Click the “Finish” buttonDisplays the “THANK YOU FOR YOUR ORDER” success message and returns to the product list pageHigh
Negative Test Cases
TC_SAUCE_SHOP_006Submit the form with an empty name on the checkout information pageUser has entered the checkout information page1. 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 navigationHigh
TC_SAUCE_SHOP_007Invalid postal code format on the checkout information page (e.g., non-numeric)User has entered the checkout information page1. Enter a valid first name and last name, with postal code “ABC12”
2. Click the “Continue” button
Shows “Postal Code is invalid” and blocks navigationHigh
TC_SAUCE_SHOP_008Attempt to check out with an empty cartUser logged in with an empty cart1. Click the cart icon to enter the cart page
2. Click the “Checkout” button
Shows “Cart is empty” or blocks navigation to the checkout pageHigh
Problem User Test Cases
TC_SAUCE_SHOP_009Problem User shows abnormal product images when adding productsProblem User logged in1. 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_010Problem User total price calculation error at checkoutProblem User has added products to the cart1. 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

  1. Priority assignment: core flows (login, adding products, checkout) and key exception scenarios (empty fields, invalid data) are set to high priority.
  2. Problem User: used to verify specific abnormal behaviors (such as UI rendering errors or logic flaws).
  3. Actual Result/Status: to be filled in based on actual observations during execution (such as “Pass”, “Fail”, or “Blocked”).
  4. Tax calculation: assuming the product total is $X, the tax-inclusive total should be X * 1.08, rounded to two decimal places (e.g., $21.99 * 1.08 = $23.75).
Built with Hugo
Theme Stack designed by Jimmy