Skip to content

Chapter 5 of 7

Testing, Debugging, and Code Review

Claude Code is a capable test author when given clear scope. A good starting prompt is "Write unit tests for [function/file] covering edge cases including null inputs, empty arrays, and boundary values." For more advanced coverage, ask for "test fixtures for [model/feature] that cover: a typical case, an edge case with empty values, and a case with maximum data," or for end-to-end assurance, "Write integration tests for [feature] that test the full request/response cycle including database interactions and edge cases." If you want to harden an existing module, "Analyze [file/module] and identify untested code paths. Write tests for the most critical gaps, prioritizing error handling and edge cases" produces a focused improvement plan.

When a test is failing, hand Claude the full error and ask it to find the cause rather than guess at a fix: "This test is failing with [error message]. Read the test and the code it tests, then find and fix the root cause." For reviews, the prompt "Review [file] for code quality, potential bugs, readability issues, and adherence to best practices. Suggest specific improvements" is a strong general-purpose template, and you can apply the same shape to pull requests with "Review the changes in [files] as if doing a code review: check for bugs, security issues, missing tests, and adherence to the project's coding standards."

Specialized reviews benefit from explicit scope. For security, ask "Review [file or feature] for security vulnerabilities including XSS, SQL injection, and OWASP top 10 issues," or build security into a feature from the start with "Implement [feature] with security as the top priority. Validate all inputs, sanitize outputs, and explain any security decisions made." For performance, "Identify performance bottlenecks in [file/function] and suggest optimizations, focusing on [N+1 queries / memory usage / response time]" targets the analysis to your concern. When you are weighing options, the prompt "What are the tradeoffs between [approach A] and [approach B] for [use case]? Which would you recommend and why?" is a good way to get an opinionated answer with reasoning.

All chapters
  1. 1Getting Started with Claude Code
  2. 2Project Context and Configuration
  3. 3Reading, Searching, and Understanding Code
  4. 4Writing, Editing, and Refactoring Code
  5. 5Testing, Debugging, and Code Review
  6. 6APIs, Data, and Infrastructure
  7. 7Architecture, Documentation, and Release Workflow

Drill it

Reading is not remembering. These come from the Claude Code Prompts deck:

Q

What is Claude Code?

Claude Code is Anthropic's official AI-powered CLI tool that helps developers write, edit, debug, and understand code directly in the terminal.

Q

How do you start Claude Code?

Run `claude` in your terminal from any project directory to start an interactive session with the AI assistant.

Q

What is the key benefit of working in Claude Code's agentic mode?

Claude Code can read files, write code, run tests, and execute shell commands autonomously, completing complex multi-step tasks end-to-end.

Q

How do you give Claude Code access to your entire project?

Navigate to your project root before starting Claude Code — it will automatically have context of all files in the working directory.