Adding Tests to Support Your Changes
What you'll learn: How including tests with your code changes makes reviews smoother and proves your work behaves as intended.
When you submit a pull request with your code changes, reviewers face a challenge: they need to verify that your code actually works. Without tests, they must either trust your word, manually test it themselves, or dig through implementation details to mentally trace execution paths. That's time-consuming and error-prone.
Why Tests Matter in Pull Requests
Think of tests like showing your work on a math problem. You're not just saying "the answer is 42"—you're demonstrating how you got there and proving it's correct. Tests serve as executable documentation that shows:
- What behavior you intended to add or change
- That your code actually delivers that behavior
- That you didn't accidentally break existing functionality
What This Looks Like
When you add a new feature or fix a bug, include tests that exercise that specific change. If you fixed a bug where user input wasn't validated, add a test that submits invalid input and verifies the system handles it properly. If you added a new calculation function, add tests with various inputs to prove it computes correctly.
This doesn't mean writing perfect, comprehensive test coverage for your entire codebase right now. It means: for the specific lines you changed or added, demonstrate they work.
Benefits for Everyone
Reviewers can read your tests to understand your intent, then run them to confirm behavior. If something breaks later, these tests serve as regression protection. Future developers (including your future self) will understand how the code should behave by reading what you tested.
Key Takeaway: Including tests with your changes transforms your pull request from "trust me, this works" into "here's proof this works," making reviews faster and building confidence in your code.