A little help for your next big idea · Security and verification

How to test AI-generated code against real requirements

Give your code a small driving test.

Practice stories use made-up people and sample data. Use your own facts when you try the steps.

YOUR FIRST STEP

Write your input rules and boundary cases down first.

Then follow the worked example below. Each step has a result you can check.

Meet Clara and Her Bakery Box App

Clara owns a small bakery. She sells sweet treats in custom boxes. She asked an AI bot to build a web shop. The shop looks bright and clean. It seems like pure magic at first.

Think of AI code like an eager bakery helper. The helper mixes flour fast. Yet you still taste the bread before selling it. You check the oven heat. You do not just trust the helper blindly.

Clara pressed one big test button. A shiny green light said her shop was ready. But real life brings tricky days. Hungry buyers do not always click in order. Clara decided to test every step herself.

  • AI writes code very fast for your ideas.
  • You must still set the real business rules.
  • Testing protects your buyers from bad surprises.

Write Down the Real Rules First

Start with a contract before you check code. A contract is a clear list of project rules. It explains what good code must do. For a discount, state if it applies before or after tax.

Pick simple examples before you read the new code. Choose an easy case first. Next, pick a boundary case. A boundary is an outer edge case like an order of zero boxes.

Then pick an invalid case like negative ten boxes. Do not let the bot guess your rules. Make sure your checks look for the real business outcome. A test must catch real slips.

  • Define tax and discount order early.
  • Set rules before reading the new code.
  • Focus on results that your buyers notice.
Write Down the Real Rules First
FeatureIndependent exampleFailure to detect
Enquiry formValid submission is recorded onceSuccess message without delivery
Private recordAnother account is denied accessUI hides a record but API exposes it
Credit purchaseA repeated event does not duplicate creditRetry causes a second entitlement
NavigationBack returns to the expected screenCorrect visual state with broken history

Check the Changes Before You Celebrate

A test run may show bright green check marks. Do not celebrate quite yet. Look closely at the diff first. A diff is a view that shows lines of code that changed.

Check that the bot did not remove older tests. Sometimes a bot deletes a test to pass easily. Make sure public entry points still work. Keep your base code safe from messy surprise edits.

Watch for placeholder behavior disguised as a real connection. The code might return a fixed sample message. It might never talk to your backend. Prototypes work for demos, but not for launch day.

  • Read changed lines in the diff carefully.
  • Ensure the bot did not delete hard tests.
  • Look for fake sample data in live routes.

Use Small Tests for Each Job

Different coding problems need different test tools. Pure math calculations need a unit test. A unit test checks one tiny piece of logic alone. It runs fast and gives quick feedback.

Interactions between screens and storage need integration checks. Critical customer paths need full browser checks. Layers support each other. An isolated calculation can pass while a form screen sends the wrong input into it.

Target what eyes can see on screen. Do not search for messy hidden tags. Look for the button label itself. Also, use sandbox tools. Do not charge a real bank card to test a cart.

  • Run unit tests for discounts and pricing math.
  • Use integration checks for saving customer orders.
  • Test visible buttons and labels on real screens.

Read more: Playwright: testing best practices

Try Double Clicks and Slow Networks

Things go wrong on busy days. What happens if a phone connection gets very slow? Try clicking a submit button twice fast. A good shop only records one single order. It ignores the second click.

Try using two different user accounts. Log out of the first account. Log into the second account right away. Check if private records stay hidden. Old data must never show up by mistake.

Watch tasks that take time to finish. A progress indicator must show real work. It should not jump to done before the work finishes. When a task fails, let the user retry with ease.

  • Click the submit button twice to test duplicates.
  • Check two different accounts on the same machine.
  • Test slow network speeds and dropped connections.

Look at the Real Screen and Log

Open your app on a narrow phone screen. Menus can shift and cover up key links. Check navigation using your keyboard. Press the Tab key to move through fields. Every box should work cleanly.

Open the browser developer console. The console is a tool that logs hidden browser errors and messages. Look for red warning text when you submit forms. Clear log messages help you locate network slips.

When you fix a bug, run the test again. Check one nearby spot to catch fresh slips. Do not build giant test suites for tiny tasks. Focus on the core steps that keep your buyers safe.

  • Test layout on narrow mobile screens.
  • Check the developer console for red errors.
  • Navigate forms using only the keyboard.

Read more: Chrome: console features reference

Clara Tests the Cupcake Order Form

Clara tries her custom box form. She invents practice input for her test. Input item: Practice Cupcake Order. Buyer name: Sam Baker. Box count: -4 boxes. Discount voucher: SWEET50. Final price: Zero dollars.

The form should stop this order fast. Negative four boxes is an invalid number. Clara clicks the buy button. An alert appears: Enter at least one box. The button stays enabled for a quick fix.

Next, Clara enters thirty boxes with the voucher. The math cuts the price before adding tax. The final receipt shows the discount clearly. Clara verifies that the cart stays accurate after a refresh.

  • Put negative numbers into quantity boxes.
  • Expect a helpful error message to appear.
  • Verify that discount math applies before tax.

Testing a Clinic Booking System

Now consider a dental clinic app. A patient tries to book a teeth cleaning. The user enters an invalid date like February thirty. The form must explain the mistake in gentle, plain words.

Next, test what happens when two people pick one time slot. Patient A and Patient B both tap noon. The system must seat Patient A first. Then it must show Patient B that noon is taken.

Check that private medical notes stay hidden. Patient B must never see Patient A’s records. A strong test suite checks these privacy borders before any patient uses the clinic app.

  • Test impossible dates like February thirty.
  • Check double bookings for the same time slot.
  • Guard private medical notes from other accounts.

Avoid Common Verification Traps

Many people trust passing test runs without looking. The fix is very simple. Break the code on purpose. Change a plus sign to a minus sign. If the test still passes, your test is broken.

Another mistake is testing with real customer emails. The computer might send fifty fake receipts to real people. The fix is simple. Use safe dummy email addresses in your test box.

Do not let the AI test itself without guidance. Ask the bot to explain why a test fits the rule. You remain the master baker. The computer only helps knead the dough.

  • Break code on purpose to confirm tests catch slips.
  • Never use real customer emails during test runs.
  • Keep human control over every project rule.

Run Your Five Minute Form Drill

Pick one web form on your site today. Open it in a private browser window. Type extra long names and leave email fields blank. Watch how the page behaves when you hit submit.

Roseram can help with a task like organizing your test notes. Access and limits depend on your current plan. Keep track of what passes and what fails in one simple list. Machines write code in seconds. But only real humans know what good service feels like. Test your app today.

  • Try bad form inputs right now.
  • Use Roseram to organize your test notes.
  • Keep your human judgment in charge.
Try this AI request — add your own details

Act as a software QA specialist. Review this AI-generated order form logic. Here are our rules: discount applies before tax, minimum order is 1 box, and empty emails must be rejected. Write three test cases for normal, boundary, and invalid inputs.

Your idea. Your next step.

Put Roseram super intelligence to work.

Bring the idea you keep coming back to. Choose a Roseram plan, then give your project a clear first task. You can think it through, build a first version, and improve it as you learn.

Check current access, plan limits, and pricing before joining.

Your next step

Your quick checklist.

Tick a step as you finish it. Your ticks and feedback stay on this device. They are not public reviews.

0 of 6 complete

Was this guide useful?

Tell the community what you tried or tell us what needs fixing. Include a source if you are correcting a fact.

Your questions, answered

Should AI write all the tests too?

AI can help write test checks. But you must set the rules. You must confirm each check yourself.

What matters more than test coverage score?

Test how real people use apps. Coverage scores only count checked lines. A big score can still fail.

Can I test using real third-party services?

No. Use safe fake test spaces. These fake setups are called sandboxes. Real tools might charge your card. They might send emails to strangers.

Why did my green test pass with a bug?

Your test looked at wrong things. Break your code on purpose first. Make sure your test catches it.

Want the technical details?Open the code notes, deeper checks, and common questions.

These notes go deeper. Use the parts that fit your project. Examples are for learning; they are not claims that we tested your app.

Technical workflow: Specify examples → Review the patch → Test behavior → Check the release
A closer look at the original workflow.

Write examples before asking for tests

Begin with the feature’s contract. For a discount function, define whether the discount applies before or after tax, how rounding works and which inputs are invalid. For a form, define the accepted fields, validation failures and successful outcome. A test that follows the implementation’s accidental behavior can pass while preserving a bug.

Choose a few inputs with expected outputs you can explain without reading the generated function. Include a ordinary case, a boundary and a rejection case. When rules are ambiguous, clarify them before turning the ambiguity into a test assertion. Keep the examples with the project brief so later revisions have the same reference.

Ask the agent to distinguish a requirement from an inference. If a test expects a particular error message but the requirement only specifies a rejected operation, the test may be unnecessarily brittle. Prioritize outcomes users depend on and reserve detailed implementation assertions for contracts that truly require them.

Write examples before asking for tests
FeatureIndependent exampleFailure to detect
Enquiry formValid submission is recorded onceSuccess message without delivery
Private recordAnother account is denied accessUI hides a record but API exposes it
Credit purchaseA repeated event does not duplicate creditRetry causes a second entitlement
NavigationBack returns to the expected screenCorrect visual state with broken history

Review the diff before trusting a green test run

Read which files changed and why. Check that the patch stays within the intended feature, preserves public interfaces and avoids deleting tests that exposed a failure. Ask for an explanation of configuration and dependency changes. A green command has limited meaning if the agent silently reduced the test scope.

Look for placeholder behavior disguised as a connection: fixed success responses, sample data in a production route or a button that changes local text instead of calling the required backend. These can be reasonable prototypes when labeled clearly, but they should not pass a launch acceptance test for a working integration.

Keep the baseline and changed revision identifiable. If a failure appears, compare the patch with a known state instead of rewriting everything. Reproducibility matters more than an impressive quantity of test output. Record the exact command and environment when the result is relevant to release.

Use the smallest test that proves the intended behavior

Pure calculations are good candidates for unit tests. Interactions among authentication, validation and storage need integration checks. Critical customer journeys need browser or device checks. The layers complement each other: an isolated calculation can be correct while a screen passes the wrong input into it.

Playwright’s guidance emphasizes user-visible behavior and isolated state. In a browser test, locate the control by its accessible role and verify the outcome that matters. Avoid tying a journey to incidental CSS selectors when the same behavior can be expressed through a button name, field label or visible result.

Use controlled test services and fixtures. A test should not send real marketing messages, charge a real customer or mutate production records merely to prove that a button responds. Test integrations in the correct environment and keep their verification distinct from a mocked request. Mocks prove your response handling, not the availability of an external provider.

Illustrative acceptance test · adapt to your app
test('invalid enquiry stays recoverable', async ({ page }) => {
  await page.goto('/contact');
  await page.getByRole('button', { name: 'Send enquiry' }).click();
  await expect(page.getByText('Enter a valid email')).toBeVisible();
  await expect(page.getByRole('button', { name: 'Send enquiry' })).toBeEnabled();
});

Read more: Playwright: testing best practices

Test interruption, repetition and conflicting state

Try a slower response, a rejected request and a retry. Click a submit action twice and check whether the system records one intended result or two. Navigate away and return during pending work. Decide whether cancellation stops the underlying operation or only hides the screen; the UI should not misrepresent the server state.

Use two accounts for private data checks and two revisions for conflict checks. A workspace edit may conflict with a change made elsewhere, and a locally cached result may belong to a previous user. Check logout, account switching and project switching. These transitions often reveal state assumptions that a happy-path test does not exercise.

For long-running work, inspect stage changes and timeout behavior. A progress indicator should represent actual observed work, not a fabricated percentage that reaches completion before the operation finishes. A failure should retain enough context for a controlled retry instead of dropping the user back into an empty state.

Inspect the real browser, mobile layout and console

Test narrow screens and keyboard access. Open and close menus and dialogs, submit the main form and verify that the page remains usable after an error. Detect invisible overlays and scroll locks by interacting with the rendered page, not only measuring element rectangles.

Use the console and network view to connect an observed failure to its request or stack trace. Preserve relevant messages across navigation when reproducing a sequence, and redact credentials before sharing output. A blocked advertising request and an application state error can appear together without having the same cause.

After a repair, repeat the original failing action and one nearby regression case. Stop broadening the test set once the concrete risk and required gates are covered. A large redundant suite can slow delivery while adding less confidence than a small independently grounded set of checks.

Read more: Chrome: console features reference

Separate local checks, provider checks and deployed behavior

A useful report names the tested revision, command, environment and limitation. “Unit tests passed locally; checkout was mocked; production webhook delivery is unverified” gives a release owner actionable information. “Everything works” hides the distinctions they need.

Keep deployment checks small and purposeful. Verify the deployed route, configuration and critical journey because production can differ from local development. For a native app, use the actual packaged build. For an imported project, verify source-to-preview synchronization. Do not imply that a desktop browser test covers either condition.

Common questions

Should AI write the tests too?

It can help implement them. Define expected outcomes independently, review assertions and inspect whether the tests would fail for a plausible defect.

What is more important than code coverage?

Coverage is a useful signal, but correct requirements, meaningful assertions and critical journey checks determine what the suite actually proves.

Should tests call real third-party services?

Use controlled test environments where appropriate. Avoid unintended charges or communications, and distinguish provider verification from mocked integration behavior.

Where the facts come from

Use these links to check the technical facts. The stories here are made-up examples to help you learn. Roseram sells AI tools; our examples are not promises of results.

  1. Playwright: testing best practices ↗
    What this source covers

    Tests based on user-visible behavior and isolated test state.

  2. Chrome: console features reference ↗
    What this source covers

    Inspecting messages, stack traces and network errors.

References last reviewed 2026-10-11. Writing refreshed 2026-10-14. Spot a mistake? Tell us.