Testing with Claude Code
Use Claude Code for contract-driven unit, integration and Playwright tests, then create and verify browser acceptance tests with ContextQA MCP.
Quick answer
Claude Code can help design tests, edit test files and run the test tools already installed in your repository. Start with an independently defined expected result, generate the smallest useful test, and inspect the actual runner output. Add ContextQA MCP when you want to create and execute managed browser tests against a reachable application. ContextQA MCP does not replace your Jest, Vitest or pytest runner.
This walkthrough uses an illustrative invoice-discount change: a discount is allowed through its expiry time, cannot make the total negative, and must appear correctly in the saved invoice. Adapt the contract and paths to your application; the examples are instructions, not recorded test results.
Before you start
Have Claude Code working in the correct repository, its dependencies installed, the feature's acceptance criteria, and a disposable test environment. Identify the branch, application version and test-data reset procedure. Use test accounts and approved secret storage; do not paste production credentials into prompts.
Choose the lowest test level that can prove each behavior:
Does the discount calculation handle boundaries?
Does invoice creation persist the correct total?
Can a user apply and remove a valid discount?
Does creating, saving and reopening an invoice preserve it?
1. Establish the commands and current baseline
Start Claude Code in your repository:
cd /path/to/your/repository
claudeClaude Code supports inspecting existing tests and following repository conventions. See its official testing workflow.
Give it a bounded discovery task before requesting edits:
Keep the baseline output. A missing database or unavailable browser is an environment blocker; it is not evidence that the feature passes or fails.
2. Turn the requirement into independent examples
Agree the currency rounding and expiry rules before asking the agent to write assertions. If the requirement is silent, label the assumption for review rather than letting the current implementation become the specification.
A valuable assertion checks the amount owed. Checking only that the calculator was called, or that an object exists, does not prove pricing behavior. Control the test clock so tomorrow's date does not change the verdict.
3. Write unit and integration tests in small increments
Ask Claude to add the approved cases using the existing runner. Unit tests should isolate the calculation; integration tests should exercise the persistence boundary with a disposable database or the repository's existing test service.
For a confirmed defect, the new regression test should expose that defect before a repair and pass after it. For new behavior, an initial failure may instead mean the feature is not implemented yet. Keep the distinction in the review.
4. Add one browser journey where it adds evidence
Use the repository's browser framework. If it uses Playwright, follow the Playwright testing guide for fixtures, locators and traces.
Check which services were real and which were mocked. An intercepted save response verifies UI behavior; it does not prove that the backend stored the invoice.
5. Connect Claude Code to ContextQA MCP
For managed browser execution, add the hosted server:
In an interactive Claude Code session, open /mcp, select ContextQA and complete OAuth sign-in. Wait for the browser callback to finish. The command and authentication flow follow Claude Code's MCP documentation and the ContextQA server setup. The account must have access to the intended ContextQA workspace.
The MCP connection gives Claude tools for ContextQA. It does not make your laptop's files or localhost application reachable by a remote test runner. Use a reachable test deployment or an organization-approved network setup for your application. Confirm the actual target environment before execution.
6. Discover, create, review, execute and inspect
First make a read-only request:
Then supply the approved target URL and criteria:
After review, ask Claude to execute that specific case. The documented flow is execute_test_case, get_execution_status, then get_test_case_results and get_execution_step_details, using the IDs returned by the tools. Follow the connected schema and execution reference; do not guess IDs or reuse an older result.
Record the case ID, execution/result ID, target build, verdict, failed assertion and evidence links. A completed execution still needs a pass/fail result. A correctly rejected expired discount is a passing negative test, not a test failure.
Export the reviewed test
Ask for supported export options for that case, then choose the required framework. Inspect the returned artifact location before assuming a hosted export wrote to your laptop. Follow export and portability, review generated code, and run it in your own CI before accepting equivalence. Export is a starting point for repository ownership, not proof that every fixture or assertion transfers unchanged.
Troubleshooting and FAQ
Claude wrote tests but did not run them. Request the exact command and output. If execution is blocked, report the blocker and leave the result unverified.
The tests pass only after retries. Preserve the first failure, compare timing and fixture state, and investigate before increasing retries.
MCP is connected but finds no tests. Confirm the account, workspace and search scope. An empty search is not a connection failure. Use connection troubleshooting.
Can ContextQA run my local unit suite? Run that suite through Claude Code's repository tools. Use ContextQA for the application tests exposed by its connected tools.
Try the workflow
Connect ContextQA MCP and run your first reviewed test. To evaluate shared suites, evidence retention or team workflows, book a ContextQA demo with one representative application journey.
Last updated
Was this helpful?
