💡 Learn how to design great software in 7 steps: https://arjan.codes/designguide.
In this video, I show you a practical example of adding unit tests to existing code. This first part focuses on adding tests while not changing the original code. In the second part (coming out next week), I'll show how refactoring the code simplifies test writing while also improving the design.
NOTES:
1) There are a few things in the test setup that are not ideal, like how dates are used in the test code, using a real API key, and doing actual card charges. I'll address these things in part 2.
2) *patching* means that you're replacing a dependency in a function or method with something else. The thing that you replace it with is called a *mock* (apologies, my use of the terms in the video is a bit messy).
The code I worked on in this episode is available here: https://github.com/ArjanCodes/2022-test-existing-code.
🎓 ArjanCodes Courses: https://www.arjancodes.com/courses/
🔖 Chapters:
0:00 Intro
1:05 Explaining the example
4:10 Analysis & Setup
6:05 Adding LineItem tests
8:40 Adding Order tests
10:56 Adding PaymentProcessor tests
15:50 Analysis of the test setup so far
17:05 Adding pay_order tests
#arjancodes #softwaredesign #python