filmov
tv
How To Write Unit Tests For Existing Python Code // Part 1 of 2

Показать описание
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).
🎓 Courses:
👍 If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!
👀 Code reviewers:
- Yoriz
- Ryan Laursen
- Sybren A. Stüvel
- Dale Hagglund
🔖 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
DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!
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).
🎓 Courses:
👍 If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!
👀 Code reviewers:
- Yoriz
- Ryan Laursen
- Sybren A. Stüvel
- Dale Hagglund
🔖 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
DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!
Комментарии