AI Insights

Top tips for generating API tests leveraging AI

Top tips for generating API tests leveraging AI Ellipse

Automated API testing has always been a balancing act. On one side, speed and coverage, and on the other, maintainability, determinism, and trust. We decided to share some top tips for what would happen if you invite AI into this equation and ask it to write production-grade API tests inside a real microservice ecosystem

This article shares the results of a hands-on experiment with GitHub Copilot in agent mode, showing how AI is moving beyond toy examples and becoming a reliable contributor to automated API testing, not in theory, but in practice.

Why This Experiment Mattered 

AI-generated code is everywhere. Demos look impressive. Blog posts are optimistic. Yet one question keeps coming up in engineering teams: Can AI actually generate maintainable, framework-compliant API tests, or does it just look convincing until you run them? 

Our goal was definite: 

What we explicitly did not aim for: 

This was not about shortcuts. It was about discipline. 

The Playground: A Real Microservice System 

The system under test was a fully containerised online shop built on microservices: 

In other words, realistic complexity. 

The challenge was obvious from the start: 
API documentation existed, but it was incomplete, inconsistent, and unaware of the gateway layer. Which brings us to the most important rule of the experiment. 

One Source of Truth. No Exceptions 

For this experiment: 

Service API documentation was the only source of truth. 

No gateway docs. 
No “tribal knowledge.” 
No fixing tests to match reality. 

If the behaviour through the gateway differed from the documentation, it was treated as a bug, not something Copilot should “work around”. 

This single constraint defined everything: 

And it exposed something crucial about AI-generated testing. 

How We Actually Generated the Tests 

Letting Copilot “just generate tests” doesn’t work. It hallucinates. It invents patterns. It ignores your framework. The real breakthrough came from adding a Framework Instruction Layer

The Instruction Layer: The Missing Piece 

Before generating a single test, we created a detailed set of rules describing: 

These rules lived in Markdown files that Copilot was required to read before writing code. Think of it as teaching Copilot how your team thinks, not just what the API looks like. Without this layer, Copilot consistently: 

With it, the quality difference was dramatic. 

Prompting Is Not a Detail, It’s the System 

Once the framework rules were in place, test generation followed a strict, repeatable flow: 

  1. Define the role – Copilot acts as a Senior SDET, not a code generator. 
  2. Constrain the scope – One service, specific endpoints, and clear scenario types. 
  3. Specify scenario depth – Positive, negative, and edge cases, with examples. 
  4. Attach the API documentation – JSON files only. No hidden context. 
  5. Validate and iterate – Review style, correctness, and coverage against documentation. Fix prompts, not the code, whenever possible. 

Over time, this became less like “asking AI for help” and more like programming the generator itself

What Worked Surprisingly Well 

With the right constraints, Copilot behaved less like a junior developer and more like a very fast, literal senior engineer. 

Where Things Fell Apart 

AI is not magic, and the cracks were instructive. 

1. Prompt Size and Context Loss 

Large prompts caused Copilot to: 

Smaller, segmented tasks worked far better. 

2. “Fixing” Failing Tests 

When tests failed due to real system behaviour mismatches, Copilot often tried to: 

In other words, create false positives. Human oversight is non-negotiable. 

3. Documentation Quality Is Everything 

Incomplete or unclear documentation led directly to: 

AI doesn’t fill gaps responsibly; it guesses. 

The Real Lesson: AI Amplifies Your Discipline 

This experiment didn’t prove that AI can replace test engineers. It proved something more interesting: 

AI magnifies the quality of your existing processes, good or bad. 

Copilot didn’t remove the need for thinking. It punished the absence of it. 

So… Can AI Write Your API Tests? 

Yes, if you’re willing to do the hard work first. AI won’t save you from: 

 But if those foundations exist, it can: 

The future of test automation isn’t “AI instead of engineers”. It’s AI-guided by engineers who know exactly what they want

Raman Piatlitski, SDET
Posted 30 Mar 2026
Read more AI Insights