AI Prompts for Fixing Broken Tests After Changes

20 of the best prompts for fixing broken tests after changes, step by step across 4 stages. Works with ChatGPT, Claude, and Gemini.

AI Prompts for Fixing Broken Tests After Changes

20 of the best prompts for fixing broken tests after changes, step by step across 4 stages. Works with ChatGPT, Claude, and Gemini.

Scroll to explore

Getting Fixing Broken Tests After Changes right takes more than a single prompt. This 4-stage guide covers Diagnose the Wall, Isolate and Fix, Verify the Resolution, and more, breaking the whole process into focused steps where each prompt builds on the last. Code changes can break previously passing tests, causing unexpected failures. This disrupts development and delays releases. These prompts help developers identify, fix, and prevent such issues using Claude Code. Every prompt is optimized and runs in ChatGPT, Claude, and Gemini.

Diagnose the Wall

Review recent changes to identify what caused the tests to fail.

Identify Recent Changes

Please identify and summarize all recent changes made to the codebase that could potentially impact the existing tests. Include specific details about each change, such as the files modified, the nature of the changes (e.g., bug fixes, feature additions, refactoring), and any relevant context that explains why these changes were made. Additionally, highlight any areas where the tests may need to be updated or adjusted as a result of these changes. Format the summary in a clear and organized manner, using bullet points for each change to enhance readability.

Diagnose the Wall

Check Test Logs

Please analyze the following test logs for errors or failures: [PASTE LOGS]. Identify any specific changes that may have contributed to these failures and provide a detailed explanation of your findings. Additionally, suggest potential solutions or next steps to address the issues identified in the logs. Format your response in a structured manner, highlighting key errors and their possible causes.

Diagnose the Wall

Analyze Code Dependencies

Analyze the code dependencies in the project that may be impacted by recent changes. Provide a detailed list of these dependencies, including their versions and the specific tests that could be affected by any modifications. Additionally, explain how each dependency interacts with the codebase and the potential consequences of changes on the overall functionality. Format the response in a structured manner, categorizing dependencies by their type and indicating the level of risk associated with each.

Diagnose the Wall

Review CLAUDE.md Compliance

Please review the content of my CLAUDE.md file provided below: [PASTE CONTENT]. Analyze the document for compliance with all specified rules and guidelines. Identify any potential rule violations that may have contributed to the test failures, and provide a detailed explanation of each violation, including how it could impact the overall testing process. Additionally, suggest any necessary corrections or improvements to ensure compliance moving forward.

Diagnose the Wall

Trace Error Origins

Please help me trace the origins of the errors in my code that are causing test failures. Analyze the code and identify the specific lines or functions responsible for these issues. Provide a detailed explanation of why each identified line or function is problematic, including any relevant context about how it interacts with the rest of the code. Additionally, suggest potential solutions or fixes for each error to help me resolve the issues effectively.

Diagnose the Wall

Isolate and Fix

Focus on fixing only the changes that caused the test failures.

Revert Problematic Changes

Identify the specific changes that led to the test failures in the codebase. For each change, provide a brief description of what was altered and the reasoning behind the decision to revert it. Additionally, explain how reverting these changes will help restore the functionality of the tests and any potential impacts this may have on the overall project. Format your response as a detailed report that includes the list of changes and their implications.

Isolate and Fix

Update Affected Tests

Identify the tests that require updates due to recent changes in the codebase. Provide a detailed list of the affected tests, including their names and the specific changes that necessitate the updates. For each test, explain how the new code logic differs from the previous version and outline the necessary modifications to ensure that the tests accurately reflect the updated functionality. Finally, ensure that the updated tests are structured correctly and follow best practices for test design.

Isolate and Fix

Fix Code Logic

Please review the following code that has caused tests to fail: [INSERT CODE HERE]. Identify the specific lines where the logic is incorrect and provide a detailed explanation for each change you recommend. For each modification, include the line number, the original code, the corrected code, and a clear rationale explaining why the change is necessary to ensure the tests pass successfully. Additionally, summarize the overall impact of these changes on the functionality of the code.

Isolate and Fix

Resolve Dependency Issues

Identify and resolve any dependency issues that are impacting the functionality of the tests in the project. Please provide a detailed list of the dependencies that require fixing, including their current versions and the specific problems they are causing. Outline the steps you will take to address each dependency issue, including any updates, changes, or configurations needed to ensure that the tests run smoothly. Additionally, explain how these fixes will improve the overall test reliability and performance.

Isolate and Fix

Patch Specific Errors

Identify the specific errors listed in the test logs and provide a comprehensive explanation for each one. For every error, describe the underlying cause, the steps you will take to resolve it, and any changes made to the code or tests. Additionally, outline how you will verify that the fix is effective and ensure that similar issues do not arise in the future. Format your response in a clear, structured manner, addressing each error individually with relevant details.

Isolate and Fix

Verify the Resolution

Ensure the tests pass successfully after applying the fixes.

Run All Tests

Please execute all tests in the suite and provide a detailed output of the results. Confirm whether all tests pass successfully or if there are any failures. If there are failures, include information on which tests failed and any relevant error messages or issues encountered during the execution. Additionally, summarize the overall status of the test suite, indicating the total number of tests run and the number of tests that passed.

Verify the Resolution

Compare Before and After

Please compare the test results from before and after the recent fixes were implemented. Provide a detailed analysis that highlights any issues that were present in the initial test results and confirm whether they have been resolved in the updated results. Additionally, check for any new issues that may have emerged as a result of the changes. Summarize your findings in a clear format, including any relevant metrics or data points that illustrate the differences between the two sets of results.

Verify the Resolution

Validate Code Changes

Please validate the recent code changes by providing a detailed list of all files modified and the specific lines that were altered. For each change, confirm whether it successfully resolved the associated test failures. Additionally, analyze the changes to ensure that no new issues or problems have been introduced as a result. Summarize your findings in a clear report format, highlighting any areas of concern or further action needed.

Verify the Resolution

Check for New Failures

Please check the current test results and confirm whether any new test failures have emerged after the recent fixes. Summarize the overall test status, including the number of tests run, the number of failures, and any tests that are currently passing or failing. Additionally, provide insights into any patterns or specific areas where failures are occurring, and suggest potential next steps for addressing any new issues identified.

Verify the Resolution

Confirm Dependency Stability

Please verify the stability of all dependencies in the project. List each dependency along with its current version and indicate whether it is stable or not. If any dependencies are causing test failures, provide specific details about the failures, including error messages and the tests affected. Additionally, include any steps taken to resolve issues with unstable dependencies and evidence that confirms their stability, such as successful test results or version updates.

Verify the Resolution

Prevent Recurrence

Implement measures to avoid similar issues in the future.

Create CLAUDE.md Rule

Draft a new rule for CLAUDE.md aimed at preventing similar test failures based on recent issues encountered. The rule should clearly outline the specific conditions or practices that need to be followed to avoid these failures in the future. Include examples of what constitutes a violation of this rule and suggest any necessary actions or processes that should be implemented to ensure compliance. Format the rule in a clear and concise manner, suitable for inclusion in the existing documentation.

Prevent Recurrence

Add Code Comments

Review the following code snippet: [INSERT CODE HERE]. Add detailed comments throughout the code to highlight potential pitfalls that could lead to test failures. Each comment should explain the specific issue, why it is a concern, and suggest best practices to avoid these pitfalls. Ensure that the comments are clear and concise, making it easy for future developers to understand the risks associated with each section of the code.

Prevent Recurrence

Develop a Pre-Commit Checklist

Create a comprehensive pre-commit checklist that helps developers ensure their changes do not break existing tests. The checklist should include specific items such as: verifying that all tests pass locally, reviewing code for adherence to style guidelines, checking for any new warnings or errors, ensuring that documentation is updated, and confirming that no unnecessary files are included in the commit. Format the checklist in a clear, bullet-point style, and aim for at least 10 items to cover all critical aspects of the pre-commit process.

Prevent Recurrence

Establish Testing Protocols

Please draft a comprehensive testing protocol that outlines the steps necessary for testing changes before they are merged into the main codebase. The protocol should include sections on: the types of tests to be conducted (unit, integration, and end-to-end), the criteria for passing each test, the process for documenting test results, and the roles and responsibilities of team members involved in the testing process. Additionally, include guidelines for handling failed tests and the steps to take before a merge can be approved. Format the protocol as a clear, structured document that can be easily followed by the development team.

Prevent Recurrence

Document Dependency Management

Please create a comprehensive document that outlines best practices for managing dependencies in software development to prevent test failures. Include sections on identifying dependencies, version control strategies, and methods for monitoring and updating dependencies. Additionally, provide examples of common pitfalls and how to avoid them, as well as a checklist for maintaining a healthy dependency management process. The document should be structured with clear headings and bullet points for easy readability, and aim for a length of at least 1000 words.

Prevent Recurrence

Frequently asked questions

Why did my tests start failing after recent code changes?+

Claude Code may have introduced changes that conflict with existing tests. It runs autonomously and might not account for all test scenarios. Use the diagnostic prompts to identify and fix the specific changes causing failures.

How can I prevent breaking tests with Claude Code?+

Implement rules in your CLAUDE.md file to guide Claude Code's actions. Use the prevention prompts to create guardrails that ensure future changes do not break existing tests.

What should I do if Claude Code gets stuck in a loop?+

Interrupt the loop and use diagnostic prompts to identify where it got stuck. Adjust the CLAUDE.md rules to prevent similar loops in future sessions.

How do I ensure Claude Code follows project-specific rules?+

Regularly update your CLAUDE.md file with clear, specific rules. Use the prevention prompts to create rules that guide Claude Code's behavior effectively.

Can Claude Code handle large codebases without losing context?+

Claude Code has a fixed context window, which can lead to loss of earlier context in large codebases. Use prompts to keep it focused on the current task and update CLAUDE.md for better guidance.