Introduction
When ChatGPT first started being integrated into development processes in 2023, many QA engineers shrugged skeptically. Today, in June 2026, AI for testing is not an experiment but a basic practice. Neural networks generate tests faster than humans, cover edge cases, and integrate directly into the CI/CD pipeline. But how do you make AI write exactly what you need: unit tests, integration tests, and UI tests? In this article, I will show specific prompts, frameworks, and integration schemes used by leading teams. Get ready to automate QA automation.
Main Part
How AI Writes Unit Tests: Prompts and Frameworks
Unit tests are the most popular scenario for AI generation. Modern models (GPT-4o, Claude Opus 4) handle JUnit, pytest, and Mocha excellently. The key is to provide context.
Example prompt for Python (pytest):
Write unit tests for the following Python function using pytest. Cover: normal case, edge values, exceptions. Function: def calculate_discount(price: float, is_member: bool) -> float:
Popular frameworks for AI test generation:
| Framework | Language | AI Integration | Feature |
|---|---|---|---|
| Diffblue Cover | Java | Standalone AI | Generates tests for legacy code |
| TestPilot (GitHub Copilot) | All | Built into IDE | Real-time contextual suggestions |
| CodiumAI | Python, JS | VS Code Plugin | Code coverage analysis |
Important: AI tests often skip mutation testing. Always verify the quality of generated cases using tools like Pitest.
Integration Tests: When AI Saves Hours
Integration tests are more complex than unit tests because they require understanding connections between services. Here, AI acts as a "translator": it analyzes API documentation (OpenAPI, GraphQL schema) and generates scenarios.
Prompt for integration tests (REST API):
Based on the OpenAPI specification (attach file), generate integration tests in JavaScript (Supertest). Check: resource creation, retrieval by ID, update, deletion. Consider statuses 200, 201, 404, 500.
Tip: Use AI to generate test data (data seeding). For example, ask the neural network to create a JSON file with 50 realistic users for a PostgreSQL database.
UI Tests: Visual Testing with AI
UI tests are the Achilles' heel of automation. AI solves the problem with visual analysis (computer vision) and selector generation. Tools like Applitools Eyes and Playwright + AI plugins can:
- Compare screenshots and find regressions (visual testing).
- Generate XPath/CSS selectors from an element screenshot.
- Write Page Object models from Figma layouts.
Example prompt for Playwright:
Generate a Page Object for the login page (HTML attached). Use TypeScript. Add methods: login(username, password), getErrorMessage(), isLoggedIn().
Integrating AI Tests into the CI/CD Pipeline
For AI tests to be beneficial, they need to be automated. Here is a typical scheme:
- Pre-commit hook — AI checks changes and suggests new tests (via GitHub Actions + OpenAI API).
- Pull Request stage — AI agent (e.g., CodeRabbit) analyzes the diff and generates tests for new code.
- Nightly build — AI runs mutation testing and regression, updating the test base.
Example YAML for GitHub Actions:
name: AI Test Generator
on: [pull_request]
jobs:
generate-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Call AI API
run: |
curl -X POST https://api.gpt-4o.com/generate-tests \
-H "Authorization: Bearer ${{ secrets.AI_KEY }}" \
-d @changed_files.json
LSI Words for SEO
To make the article relevant to search queries, I have embedded key LSI terms: code coverage, regression testing, test base, mutation testing, visual testing, d
Comments