Тёмный

Python Tutorial: Unit Testing Your Code with the unittest Module 

Corey Schafer
Подписаться 1,4 млн
Просмотров 1,4 млн
50% 1

In this Python Programming Tutorial, we will be learning how to unit-test our code using the unittest module. Unit testing will allow you to be more comfortable with refactoring and knowing whether or not your updates broke any of your existing code. Unit testing is a must on any large projects and is used by all major companies. Not only that, but it will greatly improve your personal code as well. Let's get started.
The code from this video can be found at:
github.com/Cor...
Unittest assert methods:
docs.python.or...
if _name_ == '__main__' video: • Python Tutorial: if __...
OOP Series: • Python OOP Tutorials -...
✅ Support My Channel Through Patreon:
/ coreyms
✅ Become a Channel Member:
/ @coreyms
✅ One-Time Contribution Through PayPal:
goo.gl/649HFY
✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
✅ Corey's Public Amazon Wishlist
a.co/inIyro1
✅ Equipment I Use and Books I Recommend:
www.amazon.com...
▶️ You Can Find Me On:
My Website - coreyms.com/
My Second Channel - / coreymschafer
Facebook - / coreymschafer
Twitter - / coreymschafer
Instagram - / coreymschafer
#Python

Опубликовано:

 

26 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 688   
@martinmusli3044
@martinmusli3044 6 лет назад
I think you deserve roughly half of my salary, since your videos brought me into software development ;) Keep up that good work
@nat6106
@nat6106 6 лет назад
Yea, his videos are so clear! - Consider giving him some money on Patreon, if not done yet ;)
@tannermccollins23
@tannermccollins23 5 лет назад
You can give it to him
@malharjajoo7393
@malharjajoo7393 5 лет назад
@@tannermccollins23 yeah he did already.
@shivamkapoor1827
@shivamkapoor1827 5 лет назад
How to write test for flask aap?
@ShubhamGupta-qk9uq
@ShubhamGupta-qk9uq 4 года назад
*Wait , you guys getting paid?*
@ernestessien2388
@ernestessien2388 Год назад
6 years in, and this vid is still at its best. Thank you Corey. You're awesome
@siddharthsonone5751
@siddharthsonone5751 7 лет назад
The best place to learn python! videos like these add value to internet :-)
@rahulthaker694
@rahulthaker694 5 лет назад
Hey I have a doubt why do we use method why not directly use assertEqual in the class without creating a method and using self
@icanfast
@icanfast 3 года назад
The best place to *start* learning python. Go read the docs now!
@juliocardenas4485
@juliocardenas4485 2 года назад
Indeed
@HariPrasad_Chepyala
@HariPrasad_Chepyala Год назад
@@rahulthaker694 4:09 4:08
@alcatel1s508
@alcatel1s508 Год назад
@ 03:21 4:99
@hubertcombomarketing2693
@hubertcombomarketing2693 4 года назад
You're great Corey. With use of simple code editor You can explain complicated things. No greenscreen, no slides, just calm and pure explanations. English is a foreign language to me, but Your videos are so understandable, that this is not a problem. Once again thank You very much.
@Sugurous
@Sugurous 2 года назад
Corey is so good explaining that he doesn't think what he says, he goes smooth with the knowledge. Legend
@rahulkumargupta8372
@rahulkumargupta8372 2 года назад
i agree, most of the youtuber prefers to keep their videos short on small topics, but he keeps his videos long and explains in better way... that is why I prefer him over any other coders or youtubers.
@Elliria_home
@Elliria_home 3 года назад
This is just plain glorious. If there's such a thing as falling in love with code, this has got to be it. I enjoyed every moment of it. You're amazing, Corey, and you did a wonderful job of very clearly explaining all of it. From where I sit, you created a masterpiece of art. It's simply amazing. Test-driven development, here I come.
@IAhmed2010
@IAhmed2010 7 лет назад
It was a really very good moment when I found this channel. Such good, clear and no-nonsense explanations.
@hasanfares5774
@hasanfares5774 7 лет назад
in my country, there's an old saying for people with good explanations, "they give you the soup straight to your mouth with a spoon.". This is what are you actually doing I mean a very simplified explanation that even a naive would understand. Thanks for the effort and time you put in those tutorials, I wouldn't have got any of this without them.
@rotamagzine
@rotamagzine 6 лет назад
What a perfect way to put it!
@HarryPotter2095
@HarryPotter2095 4 года назад
The Netherlands? :)
@hasanfares5774
@hasanfares5774 4 года назад
@@HarryPotter2095 no Lebanon
@mostafamomtaz1827
@mostafamomtaz1827 4 года назад
@@hasanfares5774 also Egypt . I guess it is in arab countries :D
@phanorellux
@phanorellux 4 года назад
in my country we say 'pear,cook;fall into my mouth' with the literal word by word translation xD
@desihaxor5690
@desihaxor5690 5 лет назад
11:04 you can select add then press ctrl+d to select same word in lines below and then type to use multiple cursor to edit all words together.
@maxteer2800
@maxteer2800 4 года назад
You are a straight hero, my man. I'll venmo you $1 for that info. You just saved me hours of life.
@alenjose3903
@alenjose3903 4 года назад
thanks man 🙌
@sonercan4417
@sonercan4417 3 года назад
@@alenjose3903 ı didnt get it when ı press ctrl+d it deletes the line
@alenjose3903
@alenjose3903 3 года назад
@@sonercan4417 i dont remember how it worked bro. I am not using python now specifically atom at this moment. sry
@sonercan4417
@sonercan4417 3 года назад
@@alenjose3903 okay bro thx i figured out that it is only working on sublime text anyways thx for replying
@sudarsandm
@sudarsandm 5 лет назад
What kind of losers would dislike this video? Corey you are a time saver. Thanks for sharing with us the fruit of your hard work. You are one of the reasons why I am able to crack interviews and also deliver quality code at my work. Thank you once again.
@ferdinandbada8852
@ferdinandbada8852 5 лет назад
Bro, thank you so much. I am a python beginner and these tests were just giving me headaches. After watching this? I am not so uneducated anymore. Thank you and keep up the good work.
@kondaveetikrishnachaitanya2217
Corey is so good explaining that he doesn't think what he says, he goes smooth with the knowledge.
@abhinavchavali1443
@abhinavchavali1443 4 года назад
Everything about these videos are so polished, be it the title, thumbnail, or clear scripts
@rahulsriram6295
@rahulsriram6295 5 лет назад
That satisfaction I get every time I'm done with any video of yours! Thanks a lot man!
@lukemorrison8719
@lukemorrison8719 4 года назад
I get that, but because its done.
@fabioPatroni
@fabioPatroni 5 лет назад
I have already watched many videos on the internet and going through various online courses (paid ones too), and I must say this channel has the best Python videos, from beginner to advanced topics. Thank you very much!
@Aviel777Gergel
@Aviel777Gergel 2 года назад
Corey, You are more informative than the Python documentation. The main things I do on my current job, are things I`ve learned from you
@gouthamanush
@gouthamanush 6 лет назад
I am looking at all of your videos and as your videos are old, I thought lot of comments must be old. But to my surprise I see lot of latest comments which indicate lot of people still following these videos. Cheers to you bro.! I am experienced in Python and really these are the most simple and clear videos I have ever seen.! Your examples are mostly real time scenarios and they are very simple so that everyone can understand. Keep up the good work..!
@coreyms
@coreyms 6 лет назад
Thanks!
@CharlesDibsdale
@CharlesDibsdale 7 лет назад
Thanks Corey, really succinct, to the point with no waffle. You are very good at this
@coolpix807
@coolpix807 2 года назад
This is the most in depth unit testing tutorial I have seen. Very informative!
@sparky4277
@sparky4277 2 года назад
Finally found my way into my first job in software and your videos have been recommended and instrumental in pulling back so many curtains. Thank you for the clear and informative videos, you're crushing it.
@garybloomlaw
@garybloomlaw 4 года назад
Fantastic videos. I would add that the test cases can be spread across multiple classes. This allows you to group tests together so that you can make good use of setUp() and setUpClass(). For example, if you have multiple tests that require a database, you could group all those tests into a single class and have the setUpClass() method prepare the db. Tests that don't involve the db would go into other test classes. The larger the overall project, the more test classes you are likely to have.
@tamilshoutcom
@tamilshoutcom 6 лет назад
This was really good. To the point, clear and concise. Long video but went by like a breeze.
@peterkabiru5144
@peterkabiru5144 5 лет назад
I had given up on Unit Testing,.. until I watched this video... Thanks...man ..well explained
@ravir1237
@ravir1237 4 года назад
The best video for learning basic unit test automation with Python. Thank you Corey.
@VladimirTheAesthete
@VladimirTheAesthete 2 года назад
This channel taught me more about Python than anything else. Kudos!
@Karlkkaaarrll
@Karlkkaaarrll Год назад
I made my first python project without implementing a test. Judging from my experience it was really rough, It took me a lot of late night sleep just to see if a feature works the way I intended. Now I am learning testing and trying to apply it in my current project. I hope I had learn testing earlier, before proceeding to create my project. The video uses unit test, while mine was pytest, but hoping the concepts I learn here is same to be applied in pytest. Appreciate videos like these are created for free to everyone.
@nsmikov
@nsmikov 2 года назад
I like the simple way of explaining the code and mentioning how all components work. Nice!
@JayR98
@JayR98 9 месяцев назад
Those 40 min were absolutely worth it and cleared up the concept of unit tests, especially the last part about mocking was exactly what I needed!. Now I will be able to write some of the first-ever tests for my project, thanks a lot @Corey Schafer
@Barb_967
@Barb_967 4 года назад
I love the flow in your lectures; you usually respond exactly to the questions that pop up in my head. For instance: the print statements here were so very useful, this is exactly what I would do in trying to understand this on my own machine. You are an absolute life saver, Corey, thank you so much.
@victor65327
@victor65327 6 лет назад
Thanks you so much. I'm from Taiwan and still new to programming but learned a lot from you. If one day I could be as good as you, I also want to share all my skills and knowledge to other people as you did. Hope we all can make the world a bit warmer and nicer :)
@coreyms
@coreyms 6 лет назад
That's great to hear! The more teachers the better. Thanks for the kind words.
@riskzerobeatz
@riskzerobeatz 5 лет назад
Thank you. SO much better than paid videos.
@sanjarnarzullaev
@sanjarnarzullaev Год назад
Enjoy watching and learning from these tutorials. I hope that you will keep uploading new videos.
@alfiegrace9054
@alfiegrace9054 Год назад
I'm a data scientist, but some of my software engineer colleagues have encouraged me to check out testing. Thanks for the video, you've broken it down in a way that's both enjoyable and easy to follow!
@nimasarajpoor1358
@nimasarajpoor1358 3 года назад
Once I read if I can explain things in a very simple way, it means I am the master of it. Totally true. I hope not to forget to donate when I get a job.
@PravinMaske1
@PravinMaske1 Год назад
THank you @Corey.. I was struggeling to understand the very basics.. It really helped me to get on my new work.. Thanks a lot for making the community a better place!!!
@soupnoodles
@soupnoodles 3 года назад
Hey, thanks i am making an interpreter with Python and i wanted to write some tests for it. I was unaware of how to properly do python tests since i have never done them before, so watching this video cleared up a lot of doubts.
@alexnefayne4266
@alexnefayne4266 Год назад
Thankyou Corey for taking the time to share this valuble resource and doing such a good job of it.
@julianfeezell1644
@julianfeezell1644 5 месяцев назад
Amazing Videos! They are so easy to follow and well thought out. I have had a few instances where the library versions you are using have changed and your explanation of what is going on has allowed me to work through the new syntax in the updated libraries. This one is helping me so much at work at the moment.
@adarshraj1761
@adarshraj1761 3 года назад
I like watching Corey's videos after other's videos as these are more informative and adds more value.
@sharashami
@sharashami 5 лет назад
I gotta say that you just got a new fan, follower! man, I just love your videos and your approach! amazing! thank you so much for such incredible content!
@coreyms
@coreyms 5 лет назад
Thanks, Shara! Glad you find the videos helpful
@Lucy-pb4eh
@Lucy-pb4eh 5 лет назад
Your lessons are so practical, rich in content and easy to follow. I am so grateful for you to share your knowledge online!
@nhc002
@nhc002 6 лет назад
Corey, can't thank you enough for this wonderful series. Very well paced and great content! Look forward to your next one.
@ggrroonnkkhh
@ggrroonnkkhh 3 года назад
Nice now i have a guy I can check out if I am so unfamiliar with a topic that i don't really understand pythons documentation. Piece of advice to everybody: Don't ever thing videos like this are more then a brief introduction into a topic. They are crazy helpful but all they really do is give you a less frustrating way to grasp the basics without being very annoyed by pythons very own documentation. And for gods sake start using the python help function :D
@raymondklutse
@raymondklutse 4 года назад
Your tutorials are super amazing. I have learnt so much just in 2 days from your channel. Thank you.
@ChristianWilhelmsen
@ChristianWilhelmsen 4 года назад
Really great video! I have been using unit test a little, but introducing mocking and proper use of teardowns and class methods really gave me a whole new perspective. Really informative stuff.
@AbdelRahimBozx
@AbdelRahimBozx 4 года назад
I think that we could never thank you as much as you deserve. Keep it up please !
@2goXD
@2goXD 4 года назад
Very helpful video, big thank you. I wasn't able to figure it out from documentation alone.
@johanneswestman935
@johanneswestman935 3 года назад
Coming from embedded development this was a new way of testing for me. Normally we would just run stuff on our test rigs but our code base per product wasn't as massive as what I am working on now (cars). Thanks for explaining it so well.
@sinkingboat101
@sinkingboat101 3 года назад
Really well-timed step by step tutorial with all the possible unknown terms explained in a comprehensible fashion
@marazDNG
@marazDNG 3 года назад
Short intro and straight to the thing. Well prepared, simple yet clear demonstrative examples. Great video, thx man!
@anointedgeorge1646
@anointedgeorge1646 Год назад
Schafer thanks a million times. You saved me alot of time.
@julialocamuz7164
@julialocamuz7164 3 года назад
Best video of unittest, Thanks from Argentina
@KingGrio
@KingGrio 3 года назад
This is one of the clearest presentation of Python (and pytest) I've every scene. Truly demystified a lot of it.
@tribal2123
@tribal2123 6 лет назад
You have done an excellent job covering topics in your videos. I'll share the channel with my pythonista peeps.
@musakanneh5585
@musakanneh5585 3 года назад
Wonderful! Your explanations make life easier for young devs. Thanks for this ;)
@hossamnasser9717
@hossamnasser9717 Год назад
I like your simple way of explanation. Keep going!
@samsammurphy
@samsammurphy 6 лет назад
I wish I could give Corey's videos double thumbs up 👍👍
@neelojp8460
@neelojp8460 4 года назад
Thank you very much Mr. Schafer, your video is very clear and you explain that in very easy way! I like it
@fatemebahrami7309
@fatemebahrami7309 5 лет назад
You and your videos are amazing. Thanks a million for helping me getting better and better everyday.
@williamtouzalin1180
@williamtouzalin1180 7 лет назад
Corey, super video ! Seriously, I'm beginner in Python and you couldn't be clearer than that. Good job !
@michaelgohn2554
@michaelgohn2554 3 месяца назад
Great video! Clear and straight to the point thanks!
@yuriuehara325
@yuriuehara325 4 года назад
Your videos are really good! Great explanation. Please do one with Pytest and mocking
@walberflorencio
@walberflorencio 2 года назад
Best video that I've ever seen about unittest
@shaunsweeney6031
@shaunsweeney6031 6 лет назад
Really good at teaching material with good real world examples
@SwapnadeepMukherjee
@SwapnadeepMukherjee 3 года назад
Dear Corey, As I saw other people's comments also, a video on Pytest and Mocking would be great. Maybe you can extend this video and make a part two for mocking and a separate video on Pytest or vice-versa. But we need a video on both topics. It is really relevant and required. Thanks, Swapnadeep
@RLau-cb1td
@RLau-cb1td Год назад
Thank you so much for this video! You have answered questions that have puzzled me for so long.
@RoyeeTager
@RoyeeTager 6 лет назад
An excellent tutorial which demonstrates how to perform unit tests
@skylerbrown7571
@skylerbrown7571 4 года назад
This video finally helped me understand how to properly test my code thank you.
@skrolikowski
@skrolikowski 6 лет назад
Starting to love Python more and more each day.
@kumarsaikat3303
@kumarsaikat3303 2 года назад
Best video today I could find! Extraordinary!
@galinatroshkina6310
@galinatroshkina6310 2 года назад
That's a great tutorial, I would recommend it to any beginner Python developer.
@user-wc8sq7gb4t
@user-wc8sq7gb4t 6 лет назад
It is a very good introduction to unit testing with python. Thank you!
@iankamandew9777
@iankamandew9777 2 года назад
Really glad to have come accross this tutorial, subscribed!
@portfedh
@portfedh 2 года назад
I keep comming back to your videos. Thank you for such great content.
@arindammukherjee391
@arindammukherjee391 6 лет назад
Corey, you are such a saviour. Your videos are just true love. Thanks for making my life so much better owing to your channel. May God bless you.
@JorgeEscobarMX
@JorgeEscobarMX 2 года назад
This is a great tutorial for unit tests. Mock objects starts at 30:43
@JorgeEscobarMX
@JorgeEscobarMX Год назад
I came back an used this link to find about mocks, Thank you past me!
@kipyo
@kipyo Год назад
Beautifully explained with easy to understand examples!
@sixtusonyedibe1619
@sixtusonyedibe1619 Год назад
ALX brought me here. Thank you Corey!
@tedmilne
@tedmilne 4 года назад
Just what I needed - especially the part on Mock tests. Very well put together
@rachellefaroul
@rachellefaroul 7 лет назад
thanks for this well-structured video. couldn't get "requests" to import (maybe a Python 3 issue?) but the rest of the video was VERY helpful
@coreyms
@coreyms 7 лет назад
Be sure you have requests installed through your package manager (most likely pip). And allow to import requests from the employee module, you would need to have the employee module in the same directory relative to your test. There are ways to import module outside of the same directory, but for this video that is what I was doing.
@ojussinghal9562
@ojussinghal9562 3 года назад
I just love the crisp voiceover.
@burner918
@burner918 4 года назад
Thank you so much. This is such a brilliant tutorial. As a beginner to programming struggling to understand what tests are and why they even matter, your video really helped me get more than just a conceptual understanding. Really appreciate you taking the time for such a detailed video.
@GenerallyGoodMusic
@GenerallyGoodMusic 2 года назад
Did you just explain dunder in one sentence? I love you.
@experimentalhypothesis1137
@experimentalhypothesis1137 5 лет назад
when i see your name under a video, i know it will always be good quality
@DennisGentry
@DennisGentry 4 года назад
"You don't have to be an expert at tests." True. I find that the most valuable test is the first one, because it gets the ball rolling and lets you have some idea that automated builds are running, not just "compi9ling."
@gautamgupte9309
@gautamgupte9309 3 года назад
Hey Corey, This is as simple as someone can explain. Could you please add more videos on advanced testing concepts on mock objects and corresponding test scenarios.
@cgthejesh
@cgthejesh 3 года назад
very informative and good stuff for learning Python framework with Selenium
@thomasworkersen2972
@thomasworkersen2972 3 года назад
Corey is such a unsung hero
@rafaelrocha8483
@rafaelrocha8483 4 года назад
One of the most important videos ever made!
@rikiaja6998
@rikiaja6998 Год назад
Great explanation, I just start learning about unit test. You explain complex things with words that easy to understand 👍👍
@ahmadmohammad7419
@ahmadmohammad7419 4 года назад
is this man something or is he something,, anything i want to learn in python i found it here,,thank you so much man for all what you do
@ejazahmedak
@ejazahmedak 2 года назад
This is amazing! Thank you for taking the time to do this.
@saitaro
@saitaro 7 лет назад
This channel deserves more subscribers. Thank you Corey, didn't you try Visual Studio Code? It's got a built-in debugging tool which I wanted you to make a lesson about lol
@coreyms
@coreyms 7 лет назад
I have not given it a try yet. I want to when I have more free time, but I'm currently so busy that I don't have much time to explore new tools. Especially when Sublime Text is working so well for me currently. But I hope to look at VS in the future.
@soumitripattnaik
@soumitripattnaik 7 лет назад
Corey Schafer yes VS Code is really cool. Do give it a try. And I would love to see a video on it :D YOUR EXPLANATION IS SECOND TO NONE.
@mctrjalloh6082
@mctrjalloh6082 6 лет назад
I want to subscribe again but.. uhh not possible!
@DevinMork
@DevinMork 6 лет назад
Weak. Use python to write a bot that signs up for email addresses, creates RU-vid accts, and subscribes to Corey's channel!
@mctrjalloh6082
@mctrjalloh6082 6 лет назад
then waiting for another Corey's tutorial for doing that ;)
@olekodundich1501
@olekodundich1501 4 года назад
the best tutorial I've seen so far .... many thank!
@TJKhara
@TJKhara 4 года назад
@21:40 DRY - create objects once @22:22 - setup and teardown methods @25:00 - teardown @26:53 - the setup and teardown run before and after every single test what is the way to run something once at the start? @29:00 - how to deal with stuff we have no control over @29:15 - mocking
@realgecko
@realgecko 5 лет назад
I wish I found your videos earlier, when I started to learn python. Really awesome content!
@chengguanteo9080
@chengguanteo9080 3 года назад
Hi, really looking forward to your promise on pytest video! Thank you in advance!
@ighsight
@ighsight 2 года назад
Excellent. Remove a lot of the mystery for me, this actually looks doable for me now.
@ragibshahariar6852
@ragibshahariar6852 5 лет назад
Corey thank you so much i wish Allah give you hedaya. insha-allah
@ryanvb3452
@ryanvb3452 6 лет назад
I think this is the first time I managed to get through a 30 min+ programming tech tutorial without having to take a break. You've just earned yourself a new subscriber. ;) Any tutorials on Selenium?
@coreyms
@coreyms 6 лет назад
Not yet, but I plan on doing Selenium tutorials in the future.
@AlanMerrigan
@AlanMerrigan 6 лет назад
Awesome content. All of it, but I have really enjoyed in particular your bs4, json, and regex videos. Really looking forward to any Selenium or phantomJS content that may come in the future.
@lardosian
@lardosian 6 лет назад
I find that with Coreys videos, unique skill.
Далее
How To Write Unit Tests in Python • Pytest Tutorial
35:34
Brilliant Budget-Friendly Tips for Car Painting!
00:28
Avaz Oxun - Turqi sovuq kal
14:50
Просмотров 828 тыс.
5 Good Python Habits
17:35
Просмотров 539 тыс.
10 Important Python Concepts In 20 Minutes
18:49
Просмотров 131 тыс.
Thoughts About Unit Testing | Prime Reacts
11:21
Просмотров 225 тыс.
10 Python Tips and Tricks For Writing Better Code
39:21
Pytest Tutorial - How to Test Python Code
1:28:39
Просмотров 197 тыс.
Intro to Python Mocks | Python tutorial
18:42
Просмотров 84 тыс.
Brilliant Budget-Friendly Tips for Car Painting!
00:28