DEV Community

Cover image for How to Test AI Features Without Pretending They Are Deterministic
David Frei
David Frei

Posted on

How to Test AI Features Without Pretending They Are Deterministic

Traditional UI testing is built around deterministic expectations.

Enter a known value. Click a known button. Receive a known result.

AI features weaken that assumption.

A copilot may rewrite the same sentence in several acceptable ways. An assistant may offer different guidance depending on the surrounding context. A generated form value may vary while still satisfying the business rule. A coding assistant may change a component, a selector, and a test in the same pull request.

That does not make AI features untestable.

It means the test strategy has to distinguish between what is allowed to vary and what must remain invariant.

The mistake is trying to assert every generated word. The opposite mistake is asserting almost nothing because “AI is nondeterministic.”

Good AI testing lives between those extremes.

Start with the contract around the model

The model is only one part of the feature.

A production AI workflow also includes:

  • prompt construction;
  • retrieved context;
  • user permissions;
  • input validation;
  • output parsing;
  • moderation or policy checks;
  • retries and timeouts;
  • UI state;
  • undo and recovery;
  • persistence;
  • audit logging;
  • downstream side effects.

Many serious failures occur outside the model itself.

The generated text may be reasonable, but inserted into the wrong field. The suggestion may be correct, but applied twice. The user may click Undo and see the UI revert while the saved record remains changed. A retry may create duplicate side effects.

That is why browser-level testing matters. It exercises the AI feature as a product workflow, not as an isolated prompt.

Testing AI-Assisted Forms with Endtest: Inline Guidance, Validation Recovery, and Workflow Coverage is a useful example of that broader perspective.

Assert invariants, not exact prose

Suppose an AI assistant rewrites a support response.

An overly strict test compares the full output with a stored paragraph. That test fails whenever the wording changes, even if the result improves.

An overly loose test checks only that some text appeared. That test passes when the assistant produces irrelevant, unsafe, or malformed content.

A better test verifies stable properties:

  • the output is not empty;
  • required facts are preserved;
  • prohibited claims are absent;
  • the response stays within a length limit;
  • placeholders are removed;
  • the correct language is used;
  • formatting remains valid;
  • the user can accept, edit, reject, and regenerate;
  • the action does not modify unrelated fields.

Some properties can be checked with deterministic code. Others may use semantic or AI-based assertions. The important part is defining the business contract first.

Editing copilots need reversible workflows

AI copilots increasingly edit existing content instead of merely generating new content.

That creates state transitions:

  1. Original content.
  2. Suggested change.
  3. Preview or diff.
  4. Accepted edit.
  5. Manual adjustment.
  6. Undo.
  7. Redo or regenerate.
  8. Saved result.

Each transition deserves testing.

A common defect is that Undo restores the visible text but not the underlying form state. Another is that accepting a second suggestion applies it to the original content rather than the currently edited version. A third is that a background autosave persists a suggestion before the user accepts it.

What to Check in a Browser Testing Platform for AI Copilots With Inline Edits, Undo, and Revert Flows provides a strong checklist for these interactions.

The related review, Testing AI Copilots That Edit Forms and Rewrite Copy, looks specifically at using Endtest for workflows where an AI action can trigger broader side effects.

The central testing question is not merely “Was the suggestion good?”

It is:

Did the product give the user control over what changed, when it changed, and how to recover?

Validation recovery is as important as generation

AI-assisted forms often promise to help users recover from validation errors.

That sounds straightforward until the assistant receives partial or contradictory state.

Imagine a form with an invalid date, missing address, and unsupported currency. The assistant might:

  • fix one field but not the others;
  • overwrite a valid field;
  • suggest a value the user is not allowed to select;
  • clear an error visually without updating the submitted payload;
  • enter a value that passes client-side validation but fails server-side validation.

Test the whole recovery loop:

  1. Create a known invalid state.
  2. Trigger AI guidance.
  3. Verify which fields the assistant proposes changing.
  4. Confirm that unaffected fields remain intact.
  5. Apply the suggestion.
  6. Submit the form.
  7. Verify the server-side result.
  8. Undo or revise the suggestion.
  9. Confirm that the new state persists correctly.

The purpose is not to prove that the model always chooses the same correction. It is to prove that every allowed correction remains inside the product’s rules.

Generated test steps still need governance

AI is also entering the testing process itself. Tools can generate test cases, steps, locators, assertions, and failure explanations.

This can accelerate coverage, but it creates a governance problem.

Who approved the generated test? Which instructions produced it? What changed after generation? Was the locator manually corrected? Did a reviewer accept the assertion? Can the team reconstruct why a step exists six months later?

What to Check in a Test Case Management Tool for AI-Generated Steps, Manual Review, and Audit Trails addresses these questions directly.

Treat generated tests like generated code:

  • keep a review step;
  • preserve authorship and timestamps;
  • record material changes;
  • expose the generated-versus-edited distinction;
  • prevent silent replacement of approved steps;
  • make rollback possible;
  • retain evidence from execution.

Speed is valuable. Untraceable speed is expensive later.

Release sign-off needs evidence people can trust

A pass/fail badge is rarely enough for an AI-heavy workflow.

Reviewers may need to see:

  • the original input;
  • the generated output;
  • the expected invariants;
  • screenshots before and after acceptance;
  • relevant network responses;
  • the saved record;
  • the identity of the model or configuration;
  • the test data and environment;
  • any manual review decision.

A Practical Look at Endtest for AI UI Regression Reviews, Evidence Capture, and Release Sign-Off explores how a test platform can support that evidence chain.

Evidence should be selective. Capturing everything creates noise and may retain sensitive data unnecessarily. Capture the information needed to explain the decision.

The goal is not to make every release reviewer inspect every AI response. The goal is to make suspicious failures and important changes reconstructable.

When AI-generated code breaks tests, log the change context

AI coding assistants can introduce failures that are hard to diagnose because they modify several layers at once.

A generated change may:

  • rename a component;
  • restructure the DOM;
  • remove a test attribute;
  • alter timing;
  • update application code but not fixtures;
  • “fix” the failing test by weakening the assertion;
  • introduce an environment-dependent dependency.

When CI fails, the most useful logs connect the test failure to the code change.

What to Log When AI Coding Assistants Break Frontend Tests in CI recommends capturing enough context to understand both sides.

At minimum, it helps to preserve:

  • the failed step and locator;
  • the relevant DOM fragment;
  • console and network errors;
  • screenshots around the failure;
  • changed application files;
  • changed test files;
  • dependency changes;
  • whether the test passed before the generated patch;
  • whether retries changed the outcome.

This prevents the team from treating every failure as “just flakiness.”

Tool evaluation should include total operational cost

AI features can make testing tools look impressive in a demo. The harder question is whether the platform reduces work over time.

The license price is only one part of the cost.

Also consider:

  • onboarding;
  • training;
  • test creation;
  • review;
  • maintenance;
  • infrastructure;
  • parallel execution;
  • debugging;
  • access control;
  • evidence retention;
  • integrations;
  • migration;
  • vendor support;
  • the opportunity cost of engineers maintaining internal tooling.

How to Estimate the Real Cost of a QA Platform When Onboarding, Training, and Maintenance Are Included provides a practical framework.

For teams comparing AI testing vendors, AI Testing Vendor Landscape for Cost-Sensitive Teams adds two important dimensions: traceability and coverage.

A low-cost tool that generates many tests but makes failures difficult to understand may be more expensive in practice than a platform with clearer evidence and lower maintenance.

Build a layered AI test strategy

A mature strategy usually combines several layers.

Deterministic checks

Use ordinary code for rules that should never vary:

  • valid schema;
  • required fields;
  • permissions;
  • database state;
  • side-effect count;
  • allowed destinations;
  • successful save;
  • undo behavior.

Bounded semantic checks

Use semantic evaluation for outputs that can vary but must satisfy a defined purpose:

  • preserving required meaning;
  • avoiding prohibited content;
  • matching tone constraints;
  • including key facts;
  • remaining relevant to the input.

Human review

Reserve manual review for high-impact or difficult-to-formalize decisions:

  • legally sensitive wording;
  • brand-critical content;
  • unusual edge cases;
  • new model behavior;
  • low-confidence results.

Production monitoring

Tests cannot anticipate every prompt and context. Monitor real usage for:

  • rejection rate;
  • edit rate;
  • undo rate;
  • regeneration rate;
  • latency;
  • timeout rate;
  • validation failures;
  • escalation patterns.

Each layer catches a different class of failure.

Nondeterministic does not mean unknowable

You may not know the exact sentence an AI feature will produce.

You can still know that:

  • the user remained in control;
  • required facts were preserved;
  • unrelated data was untouched;
  • validation rules were respected;
  • side effects happened once;
  • permissions were enforced;
  • changes could be reversed;
  • evidence was captured;
  • failures could be explained.

Those are strong, testable contracts.

The best AI test suites do not pretend the model is deterministic. They make the surrounding product deterministic enough to trust.

Top comments (1)

Collapse
 
topstar_ai profile image
Luis Cruz

I particularly appreciated the section on "Assert invariants, not exact prose" as it highlights the importance of defining a business contract for AI features. The example of testing an AI assistant's rewritten support response by verifying stable properties such as required facts, prohibited claims, and length limits resonated with me. In my own experience with testing AI-powered chatbots, I've found that focusing on these invariants rather than exact wording has greatly improved test reliability. Have you found any specific challenges in balancing the level of assertion detail when testing AI features, and how do you determine which properties to prioritize?