2026-10-26•10 min•AI Engineering

AI Can Write Your Tests. Can You Trust What They Check?

The testing-philosophy skill aims for thorough coverage and tests that catch consequential mistakes. A workspace invitation shows how to choose cases, justify expected results, and decide what evidence is enough to call the work done.

AI Can Write Your Tests. Can You Trust What They Check?
AI EngineeringTestingCoding AgentsSoftware QualityVerificationAgent Skills

A test can look independent while borrowing the implementation's mistake.

The agent writes a condition, writes another condition to calculate the expected result, and reports that they agree. We now have two copies of an assumption and a green check beside them.

I want a more demanding question for every test I accept: what consequential mistake could this test expose?

I put that question at the center of the testing-philosophy skill. It guides an agent through deciding what to test, what to assert, and what evidence to ask for before calling the work done. Here’s how those choices play out for a workspace invitation.

1. Start outside the implementation

Imagine a workspace where only the named recipient can accept an invitation, and only before it expires. Acceptance adds membership to that workspace and consumes the invitation once. A rejected attempt leaves membership unchanged.

Suppose an agent implements the time check as “current time is less than or equal to expiry.” It then writes a test that calculates whether acceptance should succeed using the same comparison.

At the exact expiry time, both calculations say yes. The test can agree perfectly with incorrect behavior.

I would derive the expected result from the promise instead. For an invitation expiring at 12:00:00 UTC, an attempt at exactly 12:00:00 UTC must be rejected. That expected rejection is a fixed fact of this hypothetical requirement. It does not depend on inspecting the implementation's operator.

This separation gives us a useful disagreement: the requirement says reject; the implementation says accept. A test asserting the required rejection would expose this particular defect, provided it reaches the real time check.

If the expiry rule were unspecified, inventing a confident assertion would merely hide a product question inside the suite. I would resolve that ambiguity first.

2. Choose scenarios by what must hold

One correct deadline case does not establish that invitations work. Start with the rules that must hold across attempts, often called invariants. Here, an invitation can grant membership only to the right person in the right workspace, and it can do so only once. Each part of that promise can fail independently.

For our invented feature, I would consider at least these scenarios:

ScenarioExpected resultRisk examined
Named recipient, just before expiryOne membership for that recipient in the invited workspaceCorrect output
Attempt exactly at expiryRejected; no membership addedDeadline equality
Attempt after expiryRejected; no membership addedExpired access
Caller is signed outRejected; no membership addedAuthentication
A different signed-in person uses the invitationRejected; no membership addedRecipient authorization
Recipient supplies another workspace identifierNo membership in that workspaceWorkspace isolation
Malformed invitation codeAgreed validation response; no membership addedInvalid input
Invitation accepted againNo duplicate membership or second consumptionRepeated use and state

Follow the same reasoning for other high stakes rules. If a calculation determines a charge, assert the exact amount. If a limit protects a user, test that the system enforces it even when an upstream service returns an unexpected result. If the invitation service cannot verify who is calling and the agreed behavior is to deny access, test that failure explicitly: no membership should be created. These are cases the skill treats as required whenever a change touches the rule they protect.

The table also helps reveal shallow assertions. Checking only an error message misses the possibility that the service rejects the request after already creating membership. Where the promise includes “no change,” I want evidence about the relevant stored state.

3. Set a minimum for public boundaries

For a public API endpoint, handler, or command, the skill sets a floor: check that it rejects callers without permission, rejects invalid input with the agreed response shape, completes the happy path end to end, and keeps callers out of one another's data. These are distinct checks. An endpoint can reject someone who is signed out and still let a signed-in user reach the wrong workspace.

Run those checks at the boundary that enforces the rules. Hiding an Accept button does not show that the server would reject the same request. Then add cases for the risks specific to the feature. The minimum contract would not, on its own, catch an invitation accepted at the exact deadline or consumed twice.

4. Control uncertainty without replacing the behavior

A deadline test needs a known time. I would supply a fixed clock to the decision logic rather than wait for a real deadline to pass.

That makes “exactly at expiry” an explicit input. It also makes the result repeatable without relying on how quickly the test runner reaches an assertion.

The same reasoning applies to randomness and external services. Supply a known identifier so the test can assert exactly which record was written, or use a fake directory service that returns a fixed result. If an expired invitation must be rejected before a directory lookup, the fake can also record whether it was called. That lets the test distinguish an early rejection from one that happens only after the lookup.

But the substitute must leave the behavior under examination intact. If the invitation service is replaced by a fake that always returns “accepted,” a screen test can check how the screen handles success. It cannot establish the service's expiry or authorization rule.

For a claim about persisted membership, I would use a check that actually reaches the relevant persistence boundary. The appropriate setup depends on the application. The principle is stable: the evidence must exercise the thing the claim concerns.

5. See the test fail for the right reason

Write the expiry test before or alongside the implementation. If you’re fixing an existing bug, run it before the fix: it should show that the invitation was accepted at the exact deadline. After the fix, the same test should pass because the invitation was rejected and membership didn’t change.

Red tells you there’s a disagreement. It could be the intended bug, a timestamp you set incorrectly, or a test fixture that used an already consumed invitation.

I would inspect the inputs, the requirement, the actual result, and the exercised path before changing either side. Updating an expected value just to make the suite green destroys the useful disagreement. Changing correct code to satisfy a mistaken expectation does the same damage elsewhere.

6. Aim for high coverage and confidence

High line coverage can tell me that a suite reaches substantial portions of the implementation. I still need to ask what happened there and what the assertions would reject.

The faulty expiry test might execute the exact line containing the wrong comparison. Reaching it does not establish that the expected result is justified.

I would therefore inspect coverage alongside the meaningful scenarios. Which error branches remain untested? Are denial and isolation actually asserted? Does repeated acceptance preserve the intended state? Are the happy-path values checked precisely enough to catch a wrong workspace?

“Confidence over coverage” is a tiebreaker. If one test would catch a consequential defect and another would merely raise the line percentage, write the one that can catch the defect. In ordinary work, aim for both: cover the happy path, errors, edges, and changes in state, then make sure the assertions in each case can detect a meaningful failure. Coverage can point to paths you haven’t inspected yet; a strong suite also tells you what could go wrong on those paths.

7. Turn recurring rules into tests

Suppose every invalid invitation must return the same response shape because clients use its fields to display an error. A reviewer could remember to check that shape on every change. A test can check it every time the suite runs. The same applies to a required date format or a rule that two fields must agree. Assert the specific convention the caller depends on. If it changes on purpose, update the test in the same commit so it still describes the intended contract.

8. Run the real flow before calling it done

Now suppose the invitation decision logic is correct and its tests are meaningful. The real page still renders the Accept button permanently disabled because its loading state never clears.

The lower-level tests have not contradicted themselves. They never exercised that rendered interaction.

For this feature, I would also drive the actual acceptance flow: sign in as the intended recipient, open the invitation, interact with the rendered control, inspect the result, and confirm the resulting membership. A passing service test cannot stand in for evidence that the button works.

One successful click does not exercise the entire time and authorization matrix, either. The skill requires both passing automated tests for the underlying logic and a real run of the primary flow. If the agent lacks a test account or a needed dependency, the real check is still open. The completion report should say what remains unverified and why.

9. Use the skill on a test review

Start with a feature whose tests already pass. Give your agent the requirements and point it to the tests. Ask it to identify a promised behavior that could break while the suite stays green. For the invitation example, a useful finding would be that the expiry test never makes an attempt at the exact deadline. That gives you a specific case to add and a reason it matters.

The Testing Philosophy page in the Prompt Library has the full instructions, an example request, and a download you can install in your agent.