Test with AI · LLM Infrastructure

LLM-Powered Test Infrastructure

The quality of an AI-powered test tool depends as much on the architecture as on the model itself. Understanding how to connect a language model to your actual documentation, data, and pipelines is what separates generic output from genuinely useful test artefacts.

Test with AI CT-GenAI Ch 4 — GenAI-4.1.1 to 4.2.2 ~30 min read · ~60 min with exercises

1 The Hook

An NZ retail bank's test team spent six months building an AI-powered test case generator. They connected a general AI chatbot to their test management system. It worked — the team could ask it to produce test cases and receive a formatted list in seconds. The problem was the content. Every test case used generic banking concepts rather than the bank's actual API endpoints, field names, and business rules. References to account types used the model's invented terminology rather than the bank's product names. Validation rules described plausible but incorrect behaviour. The test cases needed substantial rewriting before they were usable. After six months, the team calculated that AI assistance had saved almost no time at all.

Then a new team member, fresh from a postgraduate AI course, suggested a different approach. Instead of connecting the chatbot to their test management system, she proposed connecting it to their internal API documentation through a technique called Retrieval-Augmented Generation. The change took a week to implement. The team loaded their API specifications, field glossary, and validation rule documentation into a vector database and wired it into the AI workflow.

The difference was immediate. The AI now generated test cases that referenced their actual endpoints, used their real field names, and reflected their specific validation rules. When a tester asked for boundary value tests on the payment amount field, the AI referenced the bank's actual limits — the same limits defined in their spec — rather than invented ones. Review time dropped from 45 minutes per test case set to about 10 minutes.

The model had not changed. The prompting style had not changed. The only thing that changed was the architecture — specifically, how context was injected into the model at query time. That is the lesson this page is built around.

The quality of an LLM-powered test tool is not determined primarily by which model you use. It is determined by how you connect the model to your system — your documentation, your test data, your historical defects, your business rules. Architecture is the lever. This module explains what that architecture looks like and how to make deliberate decisions about it.

From the field

A central government agency in Wellington was building a RAG pipeline over their internal policy library to auto-generate test cases for a new digital-services portal. The team assumed that chunking every document into 500-token pieces and dropping them into a vector store was enough — they never validated retrieval quality. In testing, the AI consistently pulled the wrong policy sections: a question about consent revocation would surface authentication guidance from an unrelated spec. The root cause was that their documents shared overlapping terminology across policy domains, so cosine similarity alone could not distinguish them. They added metadata filters (document type, policy area, version date) to every chunk and rewrote the retrieval step to pre-filter before semantic search. Retrieval precision jumped from around 40% to over 90%, and the quality of AI-generated test cases finally matched what the team had seen in the vendor demo. The lesson: the vector store is not magic — garbage-in metadata produces garbage-out context, regardless of which model sits on top.

2 The Rule

An LLM-powered test tool is a system that integrates a language model into a testing workflow to enhance automation, analysis, and decision-making. The architecture — how you connect the model to your test data, documentation, and infrastructure — determines whether it produces generic output or genuinely useful, context-aware test artefacts.

The distinction between a general AI chatbot and an LLM-powered test tool is architectural, not cosmetic. A chatbot is a model with a conversation interface. An LLM-powered test tool is a model connected to your specific domain: your specifications, your API documentation, your historical defect data. The model is the same; what surrounds it is different.

This matters practically because most test teams reach for the chatbot first. It is fast, free, and immediately available. But it produces generic output because it has no knowledge of your system. The architectural techniques in this page — RAG, agents, fine-tuning, and LLMOps — are the tools that close that gap.

3 The Analogy

Analogy

An LLM without context is like a new contractor who has read every testing textbook but has never seen your system.

They are smart and well-intentioned but will make incorrect assumptions until you show them the actual documentation. They will guess at your field names, invent your validation rules, and write test cases for a plausible version of your system that does not quite match the real one. RAG is like giving the contractor instant access to your entire internal wiki every time they answer a question. The moment they can look up your actual API documentation, your field glossary, and your defect history, their output becomes dramatically more accurate — not because they became smarter, but because they became better informed.

4 Architecture Components

CT-GenAI-4.1.1 defines the typical components of an LLM-powered test infrastructure. Understanding each component helps you diagnose why a system produces poor output and where to invest to improve it.

Front-end

The tester's interface: a chat UI, a plugin inside a test management tool like Xray or Zephyr, or a step inside a CI/CD pipeline. The front-end captures the tester's intent and hands it to the prompt processor. The quality of the interface determines how much friction exists between the tester and the AI capability.

Prompt processor

Takes the tester's request and constructs a well-structured prompt. This is where domain context is injected: system instructions that define the AI's role, retrieved document chunks from the knowledge base, and any few-shot examples. A good prompt processor is invisible to the user — they ask a simple question and the processor handles the complexity of grounding it.

LLM

The model itself. Could be cloud-hosted (accessed via API) or on-premise (deployed inside your organisation's infrastructure, required for highly sensitive data). The model processes the full prompt and generates output. The choice of model involves trade-offs between capability, cost, context window size, and data residency requirements.

External data sources

The domain knowledge your AI needs: test specifications, API documentation, previous test cases, defect history, glossaries, user story archives. These are the raw materials that make the difference between generic and context-aware output. For most test teams, this data already exists — it just needs to be structured and indexed for retrieval.

Output processor

Parses the LLM's raw text response into structured artefacts: test cases in your management tool's format, Gherkin scenarios ready for import, automation script skeletons, or defect summaries. Without an output processor, the team manually copies and reformats AI responses — a tedious step that erodes the time saving.

Security layer

Authentication (who can use the AI tool), data masking (PII and sensitive data scrubbed before leaving the network), audit logging (which tester asked what, which model version responded, which artefacts were generated), and rate limiting. In regulated industries — banking, health, government — the security layer is not optional. It is the difference between a compliant tool and a liability.

The difference between an AI chatbot and an LLM-powered test tool is that the chatbot provides only a front-end and the LLM. All the other components — the prompt processor with domain context, the external data sources, the output processor, the security layer — are what transform a general model into a tool that understands your system.

5 Retrieval-Augmented Generation

Retrieval-Augmented Generation (RAG) is the technique that addresses the most common failure mode of AI-assisted testing: the model generating test artefacts based on general knowledge rather than your actual system documentation. CT-GenAI-4.1.2 covers RAG as a foundational technique for domain-grounded AI output.

What RAG is

RAG is a technique where relevant documents are retrieved from a knowledge base and injected into the prompt at query time. The LLM generates output grounded in those documents rather than relying solely on its training data. The key phrase is "at query time" — the documents are selected dynamically based on what the tester is asking, not pre-loaded into a fixed system prompt.

Why it matters for testing

Without RAG, a model generating test cases for your payment service will invent field names that sound plausible but do not match your API. With RAG, the model retrieves the relevant sections of your API specification and generates test cases using your actual field names, your actual validation constraints, and your actual business rules. The quality improvement is direct and measurable.

How it works

  1. Your documents — specifications, API docs, test plans, defect history — are split into chunks and converted to numerical vectors by an embedding model. These vectors are stored in a vector database.
  2. When a tester asks "generate test cases for the payment endpoint", the system converts the question to a vector and searches the database for the most semantically similar document chunks.
  3. The top-matching chunks are retrieved and injected into the prompt alongside the tester's question.
  4. The model generates output grounded in those specific document chunks — your actual specification content — rather than generic knowledge.

NZ example

An NZ government agency managing an online consent platform has 200 pages of technical specifications covering privacy rules, revocation scenarios, and data sharing agreements under the Privacy Act 2020. Without RAG, a tester asking "what are the edge cases for consent revocation?" receives a generic answer about GDPR consent principles. With RAG, the system retrieves the specific spec sections covering revocation workflows, time delays, notification requirements, and exception conditions — and the AI generates test cases grounded in the actual specification.

Pro tip: RAG significantly reduces hallucination on domain-specific test tasks. If your team is generating large numbers of test cases from internal documentation, investing in a RAG setup will pay back quickly in reduced review time. Start with your highest-volume documentation source — typically API specifications or user story archives — before expanding the knowledge base.

6 LLM-Powered Agents

CT-GenAI-4.1.3 introduces LLM-powered agents: systems that can take multi-step actions in response to a goal, rather than just generating a single response to a prompt. An agent can act, observe the result, decide what to do next, and repeat until a task is complete.

Unlike a single prompt/response interaction, an agent operates in a loop:

  1. Receive a goal (e.g., "test the checkout flow for the new product category")
  2. Plan the next action (e.g., "navigate to the product listing page")
  3. Execute the action (e.g., open a browser, click the link)
  4. Observe the result (e.g., "page loaded, 24 products displayed")
  5. Decide the next step based on the observation
  6. Continue until the goal is met or the agent determines it cannot proceed

Testing use cases

Exploratory testing agent

Given a URL and a set of test objectives, the agent browses the application, identifies potentially problematic interactions, and generates a structured defect report. Useful for first-pass coverage of new features. An NZ e-commerce platform could give an agent the URL of a new product category page and ask it to explore checkout scenarios, capturing any errors or unexpected behaviour it encounters.

Regression analysis agent

Monitors a test suite over time, identifies flaky tests (tests that pass and fail without code changes), and suggests likely root causes based on test history patterns. Saves test engineers significant debugging time in large regression suites.

Test data agent

Generates and validates synthetic test data sets against a schema. Given a data model, the agent produces realistic NZ-specific test data (names, addresses, Revenue NZ numbers, Kiwisaver fund details, Coastal Bank account numbers) that satisfies field constraints without using real customer records.

Current limitations

LLM agents are still maturing. They are prone to getting stuck in loops when they encounter unexpected states, may take actions outside the intended scope, and frequently require human intervention on complex multi-step tasks. The practical recommendation is to use agents for well-defined, bounded tasks with clear success criteria — and always include human-in-the-loop checkpoints for any action that modifies data or sends requests to external systems.

7 Fine-Tuning and LLMOps

Fine-tuning

Fine-tuning (CT-GenAI-4.2.1) means taking a pre-trained model and training it further on your organisation's specific data. For testing, this could mean training a model on thousands of your team's historical test cases so it generates output that matches your exact style, format, and terminology — without needing to provide examples in every prompt.

When fine-tuning makes sense

  • You have thousands of high-quality examples in your exact format
  • You need consistent style and terminology across large volumes of generated artefacts
  • General models consistently fail at your specific domain terminology despite good prompting
  • You have the ML infrastructure to host and maintain the fine-tuned model

When fine-tuning does NOT make sense

  • You have fewer than a few hundred consistent examples (use few-shot prompting instead)
  • Your requirements change frequently — fine-tuned models become stale as your domain evolves
  • You do not have the infrastructure to deploy and serve a custom model
  • RAG + few-shot prompting already produces acceptable results at far lower cost

For most NZ test teams, RAG combined with few-shot prompting will solve the domain-specificity problem more quickly and with far less operational overhead than fine-tuning. Fine-tune only after you have exhausted simpler approaches.

LLMOps

LLMOps (CT-GenAI-4.2.2) is the practice of deploying, monitoring, and maintaining LLMs in production — the AI equivalent of DevOps. As AI becomes embedded in test pipelines, the prompts, models, and output quality need the same operational rigour as the rest of your CI/CD infrastructure.

For test teams, LLMOps means:

  • Prompt registry: Version-control your prompts. A prompt is an input to your test pipeline; changing it can change your test coverage. Track versions the same way you track code changes.
  • Output quality monitoring: Track the hallucination rate, review time, and defect detection rate of AI-generated test cases over time. If quality drifts — as model providers update their models — you want to detect it before it affects your test suite.
  • Model upgrade management: When a model provider releases a new version, your existing prompts may produce different output. Test a representative sample before promoting a new model version to production pipelines.
  • Audit trail: Record which AI-generated artefacts were used in which test runs, which model version produced them, and which tester reviewed and approved them. In regulated industries, this is not optional.

8 Common Mistakes

🚫 Using a general chatbot and expecting domain-specific output

What happens: Without context about your system, the model generates plausible-sounding test cases that use invented field names, generic validation rules, and fictional business logic. The output looks structured and professional but maps to a system that does not exist.

Correction: Either provide context in every prompt — paste in the relevant spec sections, use few-shot examples from your actual test suite — or invest in a RAG setup to automate context injection. The choice depends on volume: low-volume ad-hoc work can be handled with manual context; high-volume pipelines need RAG.

🚫 Jumping straight to fine-tuning

What happens: A team decides their AI output needs to match their house style more closely and immediately plans a fine-tuning project. Fine-tuning requires significant data collection, ML infrastructure, ongoing maintenance, and re-training when requirements change. Many teams spend months on fine-tuning projects that RAG + few-shot prompting would have solved in a week.

Correction: For most test teams, RAG + few-shot prompting solves the domain-specificity problem at a fraction of the cost and complexity. Fine-tune only when you have exhausted simpler approaches and have both the data volume and the infrastructure to sustain it.

🚫 Treating AI agents as fully autonomous

What happens: A team deploys an exploratory testing agent and assumes it will behave predictably. The agent gets stuck in a loop on an unexpected modal dialogue, makes hundreds of identical requests to the server, or — in the worst case — submits real forms or modifies data in a shared test environment.

Correction: Design agent workflows with human-in-the-loop checkpoints, especially for any action that modifies data or sends requests to external systems. Current LLM agents require oversight on complex tasks. Use agents for well-bounded, reversible tasks and monitor their execution actively during initial deployment.

🚫 Not versioning prompts used in production test pipelines

What happens: A CI/CD pipeline uses an AI model to generate regression test cases on each build. Someone tweaks the prompt to improve output on one test area. The change accidentally reduces coverage elsewhere. Because the prompt was not versioned, there is no way to identify when the change happened or roll it back.

Correction: If your pipeline uses an AI model, the prompt is part of your test infrastructure. Version it in source control, review changes through a pull request process, and record which prompt version was used in each test run. Treat prompt engineering as a development activity, not an ad-hoc adjustment.

Senior engineer insight

The moment our team stopped treating the LLM as the product and started treating the retrieval pipeline as the product, everything improved. We obsessed over which chunks got retrieved for a given query — because a bad retrieval decision upstream produced a confident, wrong test case downstream, and those are the hardest failures to catch. The model was fine; our chunking strategy and embedding choices were quietly the most impactful engineering decisions we made.

The most common mistake: teams validate that the LLM produces coherent output but never instrument the retrieval step — so they have no visibility into whether the right documents were injected in the first place.

From the field

A team building an AI test assistant for an NZ government payments API assumed that because their API documentation lived in Confluence, wiring it into a RAG pipeline would be straightforward — parse the pages, chunk them, embed them, done. What they discovered was that the Confluence export was a graveyard: pages last updated in 2019, contradictory field definitions across three versions of the same endpoint, and validation rules buried inside Word attachments that the embedding pipeline never touched. The AI generated test cases with high confidence from stale, wrong documents. After they built a documentation health gate — no page older than 12 months, no attachment-only specs — the hallucination rate on field names dropped from roughly 30 percent to under 5 percent. The lesson that generalised: a RAG pipeline is only as good as the documents you feed it, and most organisations have not thought seriously about documentation quality until an AI starts confidently surfacing the rot.

9 Now You Try

🤖 Live AI Prompt Lab — Infrastructure Design Review

An NZ e-commerce client has 500 pages of product specs, 3 years of Jira defect history, and Confluence API docs. Design an LLM-powered test infrastructure for them — describe your design below and the AI will evaluate it against CT-GenAI Chapter 4 criteria.

Show model answer prompt
Review this LLM-powered test infrastructure design for an NZ e-commerce client and provide structured feedback:

CLIENT CONTEXT:
- 500 pages of product specification documents (Word/PDF)
- 3 years of Jira defect history (JSON export available)
- Confluence wiki with REST API documentation
- Currently: testers manually read specs and write test cases
- Goal: AI-assisted test case generation

MY PROPOSED DESIGN:
1. RAG setup: Vector database containing chunked spec documents, API docs, and defect patterns
2. Front-end: Confluence plugin where testers highlight a spec section and trigger test generation
3. No fine-tuning: Use RAG + few-shot prompting instead (not enough consistent historical examples to justify fine-tuning cost)
4. LLMOps: Version-control prompts in Git, pin model version in CI/CD config, monthly quality review of a sample of AI-generated test cases

Evaluate this design against CT-GenAI Chapter 4 criteria (GenAI-4.1.1 to 4.2.2). What is strong? What is missing? What would you change?

Why teams fail here

  • Skipping retrieval validation: teams test whether the LLM output looks right but never verify which document chunks were actually retrieved — so bad retrieval silently poisons output quality with no visible signal.
  • Treating prompts as disposable config: prompts are modified ad hoc during testing sprints, never version-controlled, and when output quality regresses there is no history to diff — this is the LLMOps equivalent of editing production code without source control.
  • Data residency blind spots: teams connect a cloud-hosted LLM API to their test pipeline without checking whether the request payload contains data subject to NZ cloud sovereignty requirements or NZISM restrictions — only discovering the problem when a security audit flags the integration.
  • Not testing the pipeline on a model upgrade: the LLM provider silently updates the model version and existing prompts produce subtly different output — coverage gaps emerge in the regression suite weeks before anyone notices a trend in defect escape rates.
  • Agent scope creep: a testing agent given broad tool access (read test data, write defects, trigger builds) eventually exercises a code path the team did not anticipate — submitting duplicate defects, triggering unintended CI runs, or hitting external rate limits — because the action space was never explicitly bounded.
  • Fine-tuning before exhausting simpler options: teams invest months in a fine-tuning project to get domain-specific output when three well-crafted few-shot examples in the prompt would have achieved 90 percent of the same result in a day — fine-tuning is an operational commitment, not a one-time fix.

Why teams fail here

  • Skipping data sovereignty decisions until too late. NZ government and regulated-sector teams often build their RAG pipeline on a US-hosted cloud LLM, then discover mid-project that NZISM cloud security requirements or their agency’s data classification policy prohibit sending document chunks offshore. Retrofitting an on-premise or PROTECTED-capable model endpoint late in the project is expensive and delays delivery.
  • Treating prompt versioning as optional. A prompt silently tweaked in a shared config file causes AI-generated test cases to drop coverage of boundary conditions. Because no one versioned the change, it takes weeks to detect and there is no rollback path. Prompts are code; they belong in source control from day one.
  • Deploying agents without action scope guards. An exploratory testing agent given a UAT environment URL begins navigating to admin screens, submitting real forms, and triggering notification emails to test users. Without explicit boundaries on which URLs and HTTP methods the agent is permitted to use, “explore the app” becomes an open-ended instruction that causes real side effects.
  • Jumping to fine-tuning before exhausting RAG + few-shot. Teams underestimate the data quality required for fine-tuning: you need thousands of consistent, high-quality examples, not hundreds of ad-hoc ones. Most NZ test teams reach fine-tuning maturity only after their documentation is well-structured enough for RAG to work reliably — at which point RAG alone often solves the problem.

Key takeaway

The model is the least interesting decision you will make — what your AI knows about your system, how that knowledge reaches it, and how you govern it over time is where the real engineering lives.

10 Self-Check

Click each question to reveal the answer.

Q1. What is the key architectural difference between an AI chatbot and an LLM-powered test tool?

A chatbot is general-purpose with no domain context. An LLM-powered test tool has domain context wired in — through RAG, system prompts, or fine-tuning — so it generates output relevant to your specific system, not generic test cases. The same model can produce either result; the architecture determines which.

Q2. What problem does Retrieval-Augmented Generation (RAG) solve?

RAG grounds LLM output in your actual documentation. Without RAG, the model generates test cases from general training knowledge, leading to hallucinated field names and incorrect business rules. With RAG, the model retrieves relevant sections of your specifications, API docs, and historical test data at query time, and generates output based on those actual documents rather than invented context.

Q3. When is fine-tuning a better choice than RAG + few-shot prompting?

When you have thousands of high-quality examples in your exact format, need consistent style at scale, and have the ML infrastructure to host the fine-tuned model. For most test teams, RAG + few-shot is faster, cheaper, and easier to maintain. Fine-tune only when you have exhausted simpler approaches and have both the data volume and the infrastructure to sustain it.

Q4. What is LLMOps and why does it matter for test teams?

LLMOps is the practice of deploying, monitoring, and maintaining LLMs in production pipelines. For test teams, this means versioning prompts as source code, monitoring output quality for drift when models are updated, managing model upgrades without breaking existing test pipelines, and auditing which AI-generated artefacts were used in which test runs. In regulated industries, the audit trail is a compliance requirement.

Q5. Name two limitations of current LLM-powered testing agents.

Any two of: prone to getting stuck in loops when encountering unexpected states; may take actions outside the intended scope; require human oversight for complex multi-step tasks; struggle with multi-step reasoning across long interaction sequences; can hallucinate tool calls or make unexpected API requests; difficult to constrain to a bounded action space without careful design.

11 Interview Prep

Common interview questions on LLM-powered test infrastructure for senior testing roles.

Q: "What is RAG and how would it improve AI-generated test cases for your system?"

RAG is Retrieval-Augmented Generation — a technique that injects relevant documents from a knowledge base into the prompt at query time. For test case generation, connecting the AI to our actual API documentation and specifications means it generates test cases using our real field names, endpoints, and business rules instead of generic guesses. The model does not change; the context it receives at query time changes. We had this problem directly — our AI-generated test cases used invented field names until we wired the API spec into the prompt processor through a vector database retrieval step.

Q: "A developer asks why you are not just using a simple AI chatbot for test generation. What would you say?"

A general chatbot has no knowledge of our system. It will generate plausible-looking test cases using field names and validation rules it has invented based on patterns from its training data. Our system has specific endpoint names, specific validation constraints, and specific business rules that do not match the generic patterns in public training data. An LLM-powered test tool with our documentation wired in via RAG generates test cases that actually reflect our system — far less review time and far fewer hallucinated test conditions. For low-volume ad-hoc work, a chatbot with good manual prompting is fine. For pipeline-integrated generation at scale, the architecture matters.

Q: "How would you manage the risk of an AI-generated regression suite degrading over time as the model or prompts change?"

Version control the prompts as source code — every change goes through a pull request with a reviewer. Pin the model version in the pipeline configuration and treat a model upgrade as a change that requires testing, not just a drop-in replacement. Monitor a quality sample of AI-generated tests each sprint: review time, hallucination rate, and defect detection performance. When upgrading a model or prompt, run the new version against a representative set of previous inputs and diff the output before promoting it to production. The same discipline you apply to code changes applies to AI pipeline components.

Key takeaway

The model is not your product — the pipeline that connects it to your actual documentation, validates what it retrieves, versions what it receives, and audits what it produces is your product; get that wrong and a better model will not save you.