Using AI Large Models to Rework Testing: Test Case and Script Practices
Testing is often seen as the final gate for quality assurance, yet it suffers from repetitive work, incomplete test case coverage, and high script maintenance costs. Large language models can take on part of this workload, but their output must be reviewed by test engineers before use. This article walks through test case generation, automation scripts, human-AI division of labor, and practical prompt examples with review checkpoints for each step.
Testing has long been treated as the last line of defense for quality assurance, yet it carries persistent problems: heavy repetitive work, incomplete test case coverage, and high script maintenance costs. Large language models (LLMs) can take over part of this workload, but their output must be reviewed by test engineers before it can be used. This article covers test case generation, automation scripts, and the division of labor between humans and AI, with prompt examples and review checkpoints for each step.
1. Test Case Generation: From Writing from Scratch to Reviewing Drafts
Designing test cases is the foundation of testing and one of the most time-consuming steps. When facing a new feature, test engineers must work through business flows, UI elements, exception branches, and boundary conditions one by one. This typically takes hours, and limited perspectives can easily lead to missed scenarios.
An LLM can turn this step into “describe the requirements, then review the output.” The input can be a requirements document, a prototype screenshot, or a functional description. The more specific the prompt, the closer the draft is to being usable.
Take a login and registration feature as an example. You could prompt like this:
Here is a screenshot of a web application’s login and registration page. Please write a test case table for this feature covering the following dimensions: functional flows (normal registration, normal login); input validation (required fields, format, length limits); security checks (confirm passwords are encrypted in transit, confirm the login API has protective measures, confirm lockout triggers after consecutive failures); exception scenarios (network timeout, server-side errors, account locked); compatibility (mainstream browsers, common resolutions). For security cases, only verify that protective measures exist and that error messages are correct — do not generate attack payloads. Each case should include a case ID, priority, preconditions, steps, expected results, and the associated requirement ID.
The model can usually list conditions engineers tend to overlook, such as whether the password field allows leading or trailing spaces, whether the username is case-sensitive, or whether an old captcha becomes invalid after refreshing. The focus of the work then shifts from “writing” to “reviewing” — adding, removing, and modifying cases against business rules.
After receiving the draft, three things remain:
- Check each case against business rules and remove features the model invented, such as third-party login that the product does not actually have.
- Deduplicate. Models tend to generate semantically identical cases with slightly different steps.
- Assign a stable ID to each case and link it to a requirement ID for traceability and future maintenance.
Screenshots and requirements documents may contain real accounts, phone numbers, or customer data. Desensitize them before uploading, and confirm that the model platform’s data retention policy complies with your company’s requirements.
Narrow the Scope for Complex Business Flows
For systems with complex flows, such as e-commerce customer service, feeding the entire flow to the model at once usually produces coarse cases lacking detail. A more effective approach is to split by scenario, focusing on one business slice at a time.
- Split by user role: for example, “As a regular consumer initiating an after-sales inquiry at 10 AM, generate test cases for the core flow and cover common exception branches.”
- Split by time period or system state: for example, “During system maintenance at 2 AM, a user requests transfer to a human agent. Describe how the system should respond and generate the corresponding cases.”
After splitting, the cases for each slice are more specific and easier to review one by one.
2. Automation Scripts: Let the LLM Generate the Skeleton, Humans Handle Execution and Auditing
The workload of automation scripts is concentrated in framework usage, element location, wait handling, and ongoing maintenance. An LLM can quickly generate a script skeleton, but the generated code must be adjusted to match the team’s environment and conventions.
Most mainstream IDEs support AI assistant plugins. After selecting a requirement description or comment, the plugin can generate test code directly. This approach avoids context switching and works well for rapid drafting.
Below is an example of an API response time monitoring script. This kind of requirement is error-prone because “run every 5 minutes” is a scheduling concern and should not be implemented as a resident loop inside the test function. The prompt needs to clearly state the execution model, dependencies, and configuration:
Please write a command-line program in Go 1.22 using only the standard library. Requirements:
- On each run, send one HTTP GET request to the endpoint specified by the TARGET_URL environment variable. The timeout is configured via the TIMEOUT_MS environment variable, defaulting to 3000 milliseconds.
- Use net/http/httptrace to record DNS resolution time, TTFB (time to first byte), and total duration.
- Use log/slog for structured logging. Output a WARN-level log when total duration exceeds 500 milliseconds; output an ERROR-level log and exit with a non-zero code when the request fails or returns a non-2xx status code.
- Retry up to 2 times on failure, with a 1-second interval between retries.
- Write tests in a table-driven style, using httptest to simulate four cases: normal response, slow response, timeout, and 500 error.
- Add a comment to each function describing its responsibility. The program must not contain a resident loop; scheduled execution is handled by an external scheduler.
This prompt spells out dependencies, configuration, log levels, and scheduling boundaries, so the model’s output is more likely to run directly. Two points to note:
- Scheduling example: configure
*/5 * * * *in crontab to run the program, or set up a scheduled trigger in a CI pipeline. - Log level: slog’s warning level is named WARN. If your team’s convention requires WARNING, unify it in the log format.
Before running, also confirm the following:
- The runtime environment uses Go 1.22 or later.
- The machine running the program can reach the target endpoint and is allowed through network policies.
- If the endpoint requires authentication, inject the token via environment variables or a secrets management service — never write it into code or logs.
- The scheduling account has only the minimum permissions needed to read that endpoint.
Model-generated code must not go straight to production. Complete three checks before release: a manual code audit to confirm there are no hardcoded addresses or secrets; dependency and toolchain vulnerability scanning to check whether the Go version in use has known issues; and execution in an isolated sandbox environment to confirm that timeouts, retries, and exit codes behave as expected.
Complementary Strengths of AI and Humans
When preparing test data, AI can derive boundary value combinations beyond conventional thinking, such as special characters, overly long fields, and combinations of Unicode characters with mixed encodings. Human-prepared test data often relies on historical templates with limited coverage.
AI-generated combinations require human filtering. Test engineers should remove values that do not apply to the current system, judge which combinations have genuine testing value, and then add them to the test case library.
3. Human-AI Division of Labor and Skill Requirements
AI is better suited to repetitive, structured work. Test strategy, risk judgment…
