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

ArjanCodes ยท Beginner ยท๐Ÿ—๏ธ Systems Design & Architecture ยท3y ago
๐Ÿ’ก 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. ๐Ÿ’ฌ Join my Discord server: https://discord.arjan.codes. โŒจ๏ธ Keyboard Iโ€™m using: https://amzn.to/49YM97v. ๐Ÿ”– 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
Watch on YouTube โ†— (saves to browser)
Sign in to unlock AI tutor explanation ยท โšก30

Playlist

Uploads from ArjanCodes ยท ArjanCodes ยท 56 of 60

1 Full stack WEB DEVELOPMENT in 2021 - the ULTIMATE tech stack for FAST web app development
Full stack WEB DEVELOPMENT in 2021 - the ULTIMATE tech stack for FAST web app development
ArjanCodes
2 FROM PRODUCT IDEA TO SOFTWARE - turn your idea into reality in a few steps
FROM PRODUCT IDEA TO SOFTWARE - turn your idea into reality in a few steps
ArjanCodes
3 Cohesion and Coupling: Write BETTER PYTHON CODE Part 1
Cohesion and Coupling: Write BETTER PYTHON CODE Part 1
ArjanCodes
4 Build a GLASSMORPHISM React Component - Typescript & Material-UI
Build a GLASSMORPHISM React Component - Typescript & Material-UI
ArjanCodes
5 Observer Pattern Tutorial: I NEVER Knew Events Were THIS Powerful ๐Ÿš€
Observer Pattern Tutorial: I NEVER Knew Events Were THIS Powerful ๐Ÿš€
ArjanCodes
6 100% CODE COVERAGE - Think You're Done? Think AGAIN.โ˜
100% CODE COVERAGE - Think You're Done? Think AGAIN.โ˜
ArjanCodes
7 Two UNDERRATED Design Patterns ๐Ÿ’ก Write BETTER PYTHON CODE Part 6
Two UNDERRATED Design Patterns ๐Ÿ’ก Write BETTER PYTHON CODE Part 6
ArjanCodes
8 1000 Subscribers! ๐Ÿš€ WHY I Started this Channel and WHAT'S NEXT
1000 Subscribers! ๐Ÿš€ WHY I Started this Channel and WHAT'S NEXT
ArjanCodes
9 Channel Trailer ArjanCodes - March 2021
Channel Trailer ArjanCodes - March 2021
ArjanCodes
10 Exception Handling Tips in Python โš  Write Better Python Code Part 7
Exception Handling Tips in Python โš  Write Better Python Code Part 7
ArjanCodes
11 Monadic Error Handling in Python โš  Write Better Python Code Part 7B
Monadic Error Handling in Python โš  Write Better Python Code Part 7B
ArjanCodes
12 GW BASIC Games I Wrote When I Was a Kid ๐ŸŽฎ Running 30 Year Old Code
GW BASIC Games I Wrote When I Was a Kid ๐ŸŽฎ Running 30 Year Old Code
ArjanCodes
13 Why You Should Think About SOFTWARE ARCHITECTURE in Python ๐Ÿ’ก
Why You Should Think About SOFTWARE ARCHITECTURE in Python ๐Ÿ’ก
ArjanCodes
14 Uncle Bobโ€™s SOLID Principles Made Easy ๐Ÿ€ - In Python!
Uncle Bobโ€™s SOLID Principles Made Easy ๐Ÿ€ - In Python!
ArjanCodes
15 QUESTIONABLE Object Creation Patterns in Python ๐Ÿค”
QUESTIONABLE Object Creation Patterns in Python ๐Ÿค”
ArjanCodes
16 If Youโ€™re Not Using Python DATA CLASSES Yet, You Should ๐Ÿš€
If Youโ€™re Not Using Python DATA CLASSES Yet, You Should ๐Ÿš€
ArjanCodes
17 CODE ROAST: Yahtzee - New Python Code Refactoring Series!
CODE ROAST: Yahtzee - New Python Code Refactoring Series!
ArjanCodes
18 7 UX Design Tips for Developers
7 UX Design Tips for Developers
ArjanCodes
19 Going All-in on Software Design in Python + an ANNOUNCEMENT ๐ŸŽ™
Going All-in on Software Design in Python + an ANNOUNCEMENT ๐ŸŽ™
ArjanCodes
20 ๐ŸŽ™ Interview with Sybren Stรผvel, Developer @ Blender 3D
๐ŸŽ™ Interview with Sybren Stรผvel, Developer @ Blender 3D
ArjanCodes
21 Do We Still Need Dataclasses? // PYDANTIC Tutorial
Do We Still Need Dataclasses? // PYDANTIC Tutorial
ArjanCodes
22 7 Python Mistakes That Instantly Expose Junior Developers
7 Python Mistakes That Instantly Expose Junior Developers
ArjanCodes
23 Answering Your Most Frequently Asked Python Questions // Q&A 07-2021
Answering Your Most Frequently Asked Python Questions // Q&A 07-2021
ArjanCodes
24 GitHub Copilot ๐Ÿค– The Future of Software Development?
GitHub Copilot ๐Ÿค– The Future of Software Development?
ArjanCodes
25 More Python Code Smells: Avoid These 7 Smelly Snags
More Python Code Smells: Avoid These 7 Smelly Snags
ArjanCodes
26 Test-Driven Development In Python // The Power of Red-Green-Refactor
Test-Driven Development In Python // The Power of Red-Green-Refactor
ArjanCodes
27 5 Tips To Keep Technical Debt Under Control
5 Tips To Keep Technical Debt Under Control
ArjanCodes
28 Refactoring A Tower Defense Game In Python // CODE ROAST
Refactoring A Tower Defense Game In Python // CODE ROAST
ArjanCodes
29 The Factory Design Pattern is Obsolete in Python
The Factory Design Pattern is Obsolete in Python
ArjanCodes
30 Why the Plugin Architecture Gives You CRAZY Flexibility
Why the Plugin Architecture Gives You CRAZY Flexibility
ArjanCodes
31 Refactoring A Data Science Project Part 1 - Abstraction and Composition
Refactoring A Data Science Project Part 1 - Abstraction and Composition
ArjanCodes
32 Refactoring A Data Science Project Part 2 - The Information Expert
Refactoring A Data Science Project Part 2 - The Information Expert
ArjanCodes
33 Refactoring A Data Science Project Part 3 - Configuration Cleanup
Refactoring A Data Science Project Part 3 - Configuration Cleanup
ArjanCodes
34 Purge These 7 Code Smells From Your Python Code
Purge These 7 Code Smells From Your Python Code
ArjanCodes
35 Running A Software Development YouTube Channel
Running A Software Development YouTube Channel
ArjanCodes
36 Refactoring A PDF And Web Scraper Part 1 // CODE ROAST
Refactoring A PDF And Web Scraper Part 1 // CODE ROAST
ArjanCodes
37 Refactoring A PDF And Web Scraper Part 2 // CODE ROAST
Refactoring A PDF And Web Scraper Part 2 // CODE ROAST
ArjanCodes
38 How To Easily Do Asynchronous Programming With Asyncio In Python
How To Easily Do Asynchronous Programming With Asyncio In Python
ArjanCodes
39 The Software Designer Mindset
The Software Designer Mindset
ArjanCodes
40 NEVER Worry About Data Science Projects Configs Again
NEVER Worry About Data Science Projects Configs Again
ArjanCodes
41 Powerful VSCode Tips And Tricks For Python Development And Design
Powerful VSCode Tips And Tricks For Python Development And Design
ArjanCodes
42 8 Python Coding Tips - From The Google Python Style Guide
8 Python Coding Tips - From The Google Python Style Guide
ArjanCodes
43 What Is Encapsulation And Information Hiding?
What Is Encapsulation And Information Hiding?
ArjanCodes
44 8 Tips For Becoming A Senior Developer
8 Tips For Becoming A Senior Developer
ArjanCodes
45 Building A Custom Context Manager In Python: A Closer Look
Building A Custom Context Manager In Python: A Closer Look
ArjanCodes
46 GraphQL vs REST: What's The Difference And When To Use Which?
GraphQL vs REST: What's The Difference And When To Use Which?
ArjanCodes
47 You Can Do Really Cool Things With Functions In Python
You Can Do Really Cool Things With Functions In Python
ArjanCodes
48 Announcing The Black VS Code Theme (Launching April 1st)
Announcing The Black VS Code Theme (Launching April 1st)
ArjanCodes
49 7 DevOps Best Practices For Launching A SaaS Platform
7 DevOps Best Practices For Launching A SaaS Platform
ArjanCodes
50 Refactoring a Rock Paper Scissors Lizard Spock Game // Code Roast Part 1
Refactoring a Rock Paper Scissors Lizard Spock Game // Code Roast Part 1
ArjanCodes
51 Refactoring a Rock Paper Scissors Lizard Spock Game // Part 2
Refactoring a Rock Paper Scissors Lizard Spock Game // Part 2
ArjanCodes
52 Things Are Going To Change Around Here
Things Are Going To Change Around Here
ArjanCodes
53 Dependency Injection Explained In One Minute // Python Tips
Dependency Injection Explained In One Minute // Python Tips
ArjanCodes
54 How To Setup A MacBook Pro M1 For Software Development
How To Setup A MacBook Pro M1 For Software Development
ArjanCodes
55 A Simple & Effective Way To Improve Python Class Performance
A Simple & Effective Way To Improve Python Class Performance
ArjanCodes
โ–ถ How To Write Unit Tests For Existing Python Code // Part 1 of 2
How To Write Unit Tests For Existing Python Code // Part 1 of 2
ArjanCodes
57 How To Write Unit Tests For Existing Python Code // Part 2 of 2
How To Write Unit Tests For Existing Python Code // Part 2 of 2
ArjanCodes
58 Make Sure You Choose The Right Data Structure // Python Tips
Make Sure You Choose The Right Data Structure // Python Tips
ArjanCodes
59 5 Tips For Object-Oriented Programming Done Well - In Python
5 Tips For Object-Oriented Programming Done Well - In Python
ArjanCodes
60 Next-Level Concurrent Programming In Python With Asyncio
Next-Level Concurrent Programming In Python With Asyncio
ArjanCodes

Related AI Lessons

โšก
Goroutine Scheduling: GMP Model, Schedule Loop, Preemption & Stack Management
Learn how the Go scheduler works, including the GMP model, schedule loop, preemption, and stack management, to improve your concurrent programming skills
Dev.to ยท James Lee
โšก
Mini Program Container Architecture: How Dual-Thread Rendering Works
Learn how WeChat's Mini Program container architecture uses dual-thread rendering for improved performance
Dev.to ยท AI Super-App
โšก
I Spent 6 Months Trying to Replace Rust with Carbon -Hereโ€™s Why I Failed
Learn why replacing Rust with Carbon is challenging and what this means for systems programming
Medium ยท Programming
โšก
How to Create Architecture Overviews from Existing Code
Learn to create architecture overviews from existing code to improve documentation and understanding of your codebase
Dev.to ยท Anoop Kumar Paul

Chapters (8)

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
Up next
AWS Solution Architect Certification Roadmap 2026 | AWS Solution Architect | #Shorts #Simplilearn
Simplilearn
Watch โ†’