Prompt Engineering Basics for Testers



Prompt Engineering Basics for Testers

Prompt Engineering is the skill of writing clear, structured instructions that enable AI tools (such as ChatGPT, GitHub Copilot, Claude, or Gemini) to generate accurate and useful outputs. For software testers, prompt engineering can significantly improve productivity by automating test case creation, test data generation, automation code, API testing, bug analysis, and documentation.


Learning Objectives

After completing this topic, you will be able to:

  • Understand what Prompt Engineering is
  • Write effective prompts for testing tasks
  • Apply prompt engineering techniques
  • Generate high-quality testing artifacts using AI
  • Avoid common prompting mistakes

What is Prompt Engineering?

Definition:

Prompt Engineering is the process of designing effective prompts (instructions) that guide AI models to produce accurate, relevant, and consistent responses.

Instead of asking:

Generate test cases.

Ask:

You are a Senior QA Engineer. Generate 20 positive, negative, and boundary test cases for the Login feature in table format with Test ID, Steps, Test Data, Expected Result, Priority, and Severity.

The second prompt provides context, role, scope, and output format, resulting in much better responses.


Why Testers Need Prompt Engineering

Prompt engineering helps testers:

  • Generate test cases
  • Create automation scripts
  • Produce API test scenarios
  • Generate SQL queries
  • Create test data
  • Write bug reports
  • Analyze logs
  • Perform risk analysis
  • Generate performance test ideas
  • Create documentation

Anatomy of a Good Prompt

A good prompt typically includes:

  1. Role
    • “Act as a Senior QA Engineer.”
  2. Task
    • “Generate test cases.”
  3. Context
    • “For an online banking application.”
  4. Requirements
    • “Include positive, negative, and boundary scenarios.”
  5. Output Format
    • “Return the results in a markdown table.”

Example

Act as a Senior Test Automation Engineer.

Generate positive, negative, boundary, and security test cases for a Login page.

Include:
- Test Case ID
- Test Scenario
- Steps
- Test Data
- Expected Result
- Priority

Return the output as a markdown table.
Prompt Formula

A simple formula:

Role + Task + Context + Constraints + Output Format
Example:
Role:
Senior QA Engineer

Task:
Generate API test cases

Context:
User Registration API

Constraints:
Include positive, negative, authorization, validation, and performance scenarios

Output:
Markdown table
Types of Prompts
1. Zero-Shot Prompt

No examples are provided.

Generate test cases for Forgot Password functionality.
2. One-Shot Prompt

One example is provided.

Example:
Login → Verify successful login.
Now generate test cases for Registration.
3. Few-Shot Prompt

Multiple examples are provided to guide the AI.

Example 1:
Login

Example 2:
Search

Generate test cases for Checkout.

Effective Prompt Examples
Generate Functional Test Cases
Act as a QA Lead.

Generate 30 functional test cases for an E-Commerce Checkout page.

Include:
- Positive
- Negative
- Boundary
- Validation
Return in table format.
Generate Playwright Automation
Act as a Senior Playwright Automation Engineer.
Write Playwright TypeScript code using the Page Object Model.

Requirements:
- Use assertions
- Use async/await
- Add comments
- Handle exceptions

Generate API Test Cases
Generate API test scenarios for a Login REST API.
Include:
- Authentication
- Authorization
- Status Codes
- Invalid Requests
- Performance
- Security

Generate Bug Report
Act as a QA Engineer.

Create a professional bug report.

Include:
- Title
- Description
- Environment
- Steps to Reproduce
- Expected Result
- Actual Result
- Severity
- Priority

Common Prompting Mistakes

❌ Too vague:

Generate test cases.
✅ Better:
Generate 20 positive, negative, and security test cases for the Login page in table format.

❌ Missing context:

Write automation code.
✅ Better:
Write Playwright TypeScript automation code for the Login page using the Page Object Model and Playwright Test framework.

❌ No output format:

Generate API tests.
✅ Better:
Generate API test cases in a table with Test ID, Scenario, Request, Expected Response, and Priority.
Best Practices
  • Clearly define the AI’s role.
  • Provide business context.
  • Specify the desired output format.
  • Mention constraints (e.g., framework, language, number of test cases).
  • Break complex tasks into smaller prompts.
  • Refine prompts iteratively based on the output.

Practical Exercises

Exercise 1

Generate 20 positive and negative test cases for a Login page.


Exercise 2

Generate Playwright TypeScript automation code for the Login functionality.


Exercise 3

Generate API test cases for a Payment API.


Exercise 4

Generate boundary test cases for a Registration form.


Exercise 5

Analyze the following bug and suggest the root cause:

Login button becomes unresponsive after entering an invalid password five times.

Tags: ,
Leave a comment

Your email address will not be published. Required fields are marked *

Subscribe now

Receive weekly newsletter with educational materials, new courses, most popular posts, popular books and much more!