Performance Testing with AI: Write Scripts and Read Results

A feature can work perfectly for one user and collapse with five hundred. AI can draft scripts and summarise results, but it cannot decide what “fast enough” means for your users. In this lesson you will start performance testing with AI, read the numbers correctly and stay within safe limits.

Advertisement

📖 What You’ll Learn

  • The main types of performance tests
  • The metrics that matter most
  • How to draft a simple k6 script
  • How to read results without being misled

💡 What Is Performance Testing?

Explain Like I’m 5: Performance Testing

Imagine: One child on a slide is easy. Thirty children at once means a long queue.

What it really means: Performance testing checks how a system behaves under load.

In testing: You measure speed, errors and stability as users increase.

Test typeQuestion it answers
LoadDoes it meet goals at expected traffic?
StressWhere does it start to fail?
SpikeCan it handle a sudden jump?
SoakDoes it stay stable for a long time?

🔍 Metrics That Matter

Explain Like I’m 5: Percentiles

Imagine: Most children finish lunch in ten minutes, but a few take an hour. The average hides those slow eaters.

What it really means: A percentile shows the time that most requests met.

In testing: p95 means 95% of requests were this fast or faster.

MetricMeaning
Response timeHow long a request takes
p95 and p99Slowest experience for most users
ThroughputRequests handled per second
Error ratePercentage of failed requests
Resource useCPU, memory and database load

Averages can hide slow requests, so use percentiles too.


🧩 Get Permission First

Never load test without permission

A load test can look like an attack and can harm real users. Run it only on systems you are authorised to test. Do not use the SQA Tools practice API or any shared demo site.


🛠️ How to Do Performance Testing with AI

Start by defining your goals with the team. AI can then help turn them into a script.

Example goal: at 5 virtual users for 30 seconds, 95% of requests finish within 800 ms, and fewer than 1% fail. These numbers are examples only.

import http from 'k6/http';
import { check, sleep } from 'k6';

export const options = {
  vus: 5,
  duration: '30s',
  thresholds: {
    http_req_failed: ['rate<0.01'],
    http_req_duration: ['p(95)<800'],
  },
};

export default function () {
  const res = http.get(`${__ENV.BASE_URL}/health`);

  check(res, {
    'status is 200': (r) => r.status === 200,
  });

  sleep(1);
}

Run it against your own approved test server:

k6 run -e BASE_URL=https://your-approved-test-server.example script.js

The thresholds make the run fail if your goals are not met. sleep(1) adds a pause between requests, so that each virtual user behaves more like a real one. The script is small on purpose. Start small, and raise the load only with agreement. Confirm that the endpoint works correctly first, as covered in API Testing with AI.


📌 Reading the Results

Explain Like I’m 5: Reading a Thermometer

Imagine: One number on a thermometer tells you a little. You also ask how the child feels.

What it really means: Combine several results before making a conclusion.

In testing: Compare speed, errors and server health together.

Here are made-up results from two runs.

MetricBaselineNew build
Median response180 ms190 ms
p95 response420 ms1,250 ms
Error rate0.1%0.2%

The median barely changed, but p95 is about three times slower. Some users are now having a much worse experience. A good next step is to find which requests are slow and check server metrics.

When asking AI to summarise results, give it the real numbers and require it to separate facts from guesses.


🧪 Try It Yourself

  1. Write a performance goal for one page or endpoint, using made-up numbers.
  2. Run the prompt below to draft a script.
  3. Check every URL, the load level and the thresholds.
  4. Ask a developer or trainer to approve a small run on a local test server.
  5. Compare your p95 and median results.

📋 Ready-to-Copy Prompt

You are a performance test engineer. Draft a small k6 script.

System under test: an approved test environment, using BASE_URL.
Scenario: [user journey or endpoint]
Agreed goals: [response time and error goals]
Load: [virtual users and duration]

Rules:
- Read the URL from an environment variable.
- Do not include real credentials.
- Add thresholds based only on the agreed goals.
- Add checks for the expected response.
- Keep the load exactly as stated.

After the script, explain each option and list what I should monitor
on the server while it runs.

⚠️ Common Mistakes

  • Testing a system without permission
  • Trusting only the average response time
  • Letting AI invent performance goals
  • Running from a laptop and blaming the server for local limits
  • Forgetting to compare against a baseline

🎯 Key Takeaways

  • Performance testing shows behaviour under load.
  • Use percentiles and error rates, as well as averages.
  • Agree the goals before you write the script.
  • Load test only on systems you are allowed to test.

🎤 Interview Questions

1. What is the difference between load and stress testing?

Model answer: Load testing checks behaviour at expected traffic against agreed goals. Stress testing increases traffic beyond normal levels to find where and how the system starts to fail.

2. What does p95 mean?

Model answer: It is the value below which 95% of measurements fall. A p95 of 800 ms means that 95% of requests finished within 800 ms. It reveals slow experiences that an average can hide.

3. What is a threshold in k6?

Model answer: A threshold is a pass or fail goal for a metric, such as p95 under 800 ms. If it is not met, k6 marks the run as failed, which makes it useful in a pipeline.

4. How can AI help with performance testing?

Model answer: It can draft scripts and help summarise results. I provide agreed goals and real numbers, check the load settings and confirm conclusions with server metrics and developers.

5. What would you do if p95 increased after a release?

Model answer: I would confirm that the test conditions matched and repeat the run. Then I would find the slow requests and review server, database and dependency metrics to help locate the cause.


📝 Assignment

Create a performance test plan with a goal, a load model, metrics and a stop condition. Have AI draft the script, and record every setting you changed. Run it only on a local or approved test system.


❓ FAQ

Do I need k6 specifically?

No. JMeter, Gatling and other tools work too. The concepts remain the same.

Can Playwright be used for load testing?

It is built for browser testing and uses more resources per user. Dedicated load tools are normally a better choice, though browser timings can complement them. See Playwright with Docker for running tests at scale.


🚀 Next Steps

Well done on finishing this lesson. Complete the assignment, then continue with Accessibility and Security Testing with AI: Safe First Steps.