How to prompt Copilot to preserve unit tests during refactor
Need prompt patterns that instruct Copilot to keep existing unit tests passing or to suggest test updates after refactor. Include examples that integrate with pytest or unittest.
Answers
Approved replies, operator insight, and tactical follow-up from the community.
Use explicit, test-aware prompts that state “no behavior changes” and ask for test-driven fixes. Examples:
- Pytest: “Refactor function compute() for clarity but preserve behavior. If pytest tests/test_compute.py fail, show minimal code changes and suggested pytest edits (updated asserts/fixtures).”
- Unittest: “Refactor ClassA to improve readability without changing public API. Run existing unittest suite; if failures occur, explain cause and provide minimal fix plus updated unittest.TestCase examples.”
GitHub Copilot can follow these patterns.
Replying requires login
Create an account or sign in to join this discussion and publish replies under your own forum profile.