Testing with golang and testify - mocking - tutorial part 3

  Рет қаралды 15,193

Thomas Langhorst

Thomas Langhorst

2 жыл бұрын

This is the last part of my testify tutorial series. In this video I am going to explain how to create and use mocks. I am also reusing what we learned in part one and two and show you how to use mocks with a real world example. I am also showing some best practices and teach you to become a fully fledged testing master.
github repo:
github.com/thomaslanghorst/te...
Links:
github.com/vektra/mockery
github.com/stretchr/testify
Playlist:
• Advanced go tutorials
❤️ SUPPORT MY CHANNEL ❤️
--------------------------------------------------
A little support goes a long way!
Buy me a coffee: www.buymeacoffee.com/thomasla...
Become a patreon: / thomaslanghorst
📖 5 Books to skyrocket your career 📖
----------------------------------------------------
THE EXPLANATION VIDEO - • 5 MUST READ Programmin...
amzn.to/3IahMMh - Automate the boring stuff with python
amzn.to/3lI4RcM - Head First Design Patterns
amzn.to/3Ea1KjZ - Extreme Programming Explained
amzn.to/3k7xhwn - Soft Skills
amzn.to/3KdEC8n - Clean Code
🎒 THE GEAR I USE 🎒
--------------------------------------------------
💻 Technical Gear
amzn.to/3Edp4h5 - Apple MacBook Pro M1
amzn.to/3KmaWFQ - Laptop Bag
amzn.to/412MNdt - Apple Magic Keyboard
amzn.to/3jXJ2pb - Mouse (Mac Version)
amzn.to/3I3umwJ - Mouse (Windows Version)
amzn.to/3YHVCYD - Mousepad
amzn.to/3YAoAtj - SSD External Hard Drive
amzn.to/3Sdj0e7 - SSD Protection Case
amzn.to/3XDdfr9 - Headphones
amzn.to/3lJqrgN - USB Hub
amzn.to/3KamAUo - HDMI to USB
🎒 Digital Nomad Essential Gear
amzn.to/3Sdjn8v - Bag
amzn.to/40ZLyf9 - Bullet Journal
amzn.to/41130zS - Fineliner Pens
amzn.to/3YNwUps - French Press / Plunger
amzn.to/3lI44sk - Mug
📷 KZbin Gear
amzn.to/3k7bTra - Apple Iphone 13 mini (My "camera")
amzn.to/40ZbdEF - Tripod
amzn.to/3ZeMlY7 - Lightning to USB adapter for Microphones
amzn.to/3EdpSCD - Microphone
amzn.to/3Ee926A - Microphone Pop Protection
amzn.to/3S2AR7z - Selfie Ring Light
👋 SOCIAL MEDIA 👋
----------------------------------------------------
@the_langhorst - INSTAGRAM
@the_langhorst - TWITTER
@the_langhorst - TIKTOK
🎶 MUSIC I USED 🎶
----------------------------------------------------
Karl Casey @ White Bat Audio
• 80s Retrowave / Synthw...
Song: Erlando - Questions (Vlog No Copyright Music)
Music provided by Vlog No Copyright Music.
Video Link: • Erlando - Questions (V...
‼️ Disclaimers
The links mentioned in this description may contain affiliate links. I may receive a commission for any purchases made through these links, but there won't be any extra cost for you. I am grateful for your support, as it enables me to keep providing you with valuable content for free.
#programming #coding #golang

Пікірлер: 42
@vladf7180
@vladf7180 Жыл бұрын
It is the BEST video about this topic which I've watched! I've spent last two days improving my golang test skills and your video helps me better then other.
@ThomasLanghorst
@ThomasLanghorst Жыл бұрын
Wow, thank you so much! It makes me really happy to hear, that my videos help you! Is there another topic you would like to see as well?
@kyryloantoshyn
@kyryloantoshyn 5 ай бұрын
Go testify go! Thank you for valuable lessons! :)
@TrentRosenbaum
@TrentRosenbaum Жыл бұрын
GO TESTIFY GO!!
@JohnDoe-ji1zv
@JohnDoe-ji1zv Жыл бұрын
Very informative and straight to the point 👍🏻 thank you
@ThomasLanghorst
@ThomasLanghorst Жыл бұрын
Thank you very much! I am glad you liked it!
@fadhlirahim
@fadhlirahim 10 күн бұрын
that intro song is fire
@akshayhiremath3077
@akshayhiremath3077 16 күн бұрын
go testify go!!
@zaphkiel_3371
@zaphkiel_3371 Жыл бұрын
Awesome! Could you make another video explaining the controller-service-repository architecture in more detail?
@ThomasLanghorst
@ThomasLanghorst Жыл бұрын
Thanks for the feedback! In the next few videos, I will not do any tutorials. I want to get better at storytelling and thumbnails. But I will keep this one on my "people wanna see"-pile.
@aboba8656
@aboba8656 Жыл бұрын
GO TESTIFY GO!
@giftfelix4848
@giftfelix4848 2 жыл бұрын
This is really great.
@ThomasLanghorst
@ThomasLanghorst 2 жыл бұрын
Thank you so much! Glad you enjoyed it. Hope you actually learned something 😅
@giftfelix4848
@giftfelix4848 2 жыл бұрын
@@ThomasLanghorst Sure
@MaximRovinsky
@MaximRovinsky 2 жыл бұрын
that tutor on next up, thanks for tough staff💪
@ThomasLanghorst
@ThomasLanghorst 2 жыл бұрын
Hey again :D Thank you very much for the comment! It's really appreciated!
@AssyrianMuscle
@AssyrianMuscle Жыл бұрын
Amazing content!
@ThomasLanghorst
@ThomasLanghorst Жыл бұрын
Thank you so much. Glad you liked it!
@VincentSCHOENER
@VincentSCHOENER Жыл бұрын
I'm a bit lost between the Original struct/interface implementation and the mock one because in a normal case we don't send the reference of the object if we use the provider manually, but with the mock one, we need to send the reference (&priceProvide). Why?
@Nicholascarballo
@Nicholascarballo Жыл бұрын
Go testify Go!
@ultiumlabs4899
@ultiumlabs4899 2 жыл бұрын
thanks, it helps a lot, you've covered many areas. as for mock struct, You've explained how to test a service that calls DB repository (GET), but, I still don't know how to test a service that calls DB repository for PUT/POST (have no return value). Would you give me some references I could look up for now (and may be you could create part4). Thank you.
@ThomasLanghorst
@ThomasLanghorst 2 жыл бұрын
Hey, thanks for asking this awesome question. This is a very common usecase, so I am glad you asked! The easiest way is to check if the mock got called with the correct argument. You can do that by using the AssertCalled() function on the mock. Example: 1. let the mock know how to behave if "Insert" gets called: mockRepo.On("Insert", mock.Anything).Return(nil)
@ultiumlabs4899
@ultiumlabs4899 2 жыл бұрын
@@ThomasLanghorst thanks, I got new insight again.
@ThomasLanghorst
@ThomasLanghorst 2 жыл бұрын
Glad I can help. If you have more questions, feel free to ask anytime.
@Golandia
@Golandia 5 ай бұрын
This video promises that I will be a master in testing... let's see
@swagatochatterjee7104
@swagatochatterjee7104 Жыл бұрын
Ok, testify is indeed cool. I now can 1:1 map between Junit and Testify
@ThomasLanghorst
@ThomasLanghorst Жыл бұрын
JUnit was actually one of my favourite things about Java. Have you switched from Java to go too?
@swagatochatterjee7104
@swagatochatterjee7104 Жыл бұрын
@@ThomasLanghorst yes. The slow start and the stupendous resource hog JVM made me switch to Go. Go is C with stupidity protector built in, so that you dont shoot your foot. The only complaint I have till now is that it is kind of bit verbose. However, as they say clear is better than clever.
@ThomasLanghorst
@ThomasLanghorst Жыл бұрын
I totally agree! Go IS! verbose. But tbh, I don't mind.
@000LightWalker000
@000LightWalker000 4 ай бұрын
Go testify go🎉
@dharavathsuresh8838
@dharavathsuresh8838 4 ай бұрын
What if you want to write testcase for List and Latest functions ? How can that be done ? Mocking the entire the List and Latest functions will not give more code coverage. Is in't it ?
@vasiliyaristov7148
@vasiliyaristov7148 3 ай бұрын
Thanks
@max_ishere
@max_ishere 10 ай бұрын
Testify LETS GO
@TravisKeenan
@TravisKeenan Жыл бұрын
"GO TESTIFY GO"
@josephkoester7051
@josephkoester7051 6 ай бұрын
Yes man but great test...
@CarlosHenriqueDuartedeCarvalho
@CarlosHenriqueDuartedeCarvalho Жыл бұрын
Go testfy Go
@user-so5vj9ux7z
@user-so5vj9ux7z 4 ай бұрын
Bad tutorial
@nils.8335
@nils.8335 5 күн бұрын
I disagree
@sonamdhingra
@sonamdhingra 2 ай бұрын
GO TESTIFY GO!!
@yashkhare7308
@yashkhare7308 Жыл бұрын
GO TESTIFY GO!!
Testing with golang and testify - testing suites - tutorial part 2
19:43
Testing with golang and testify - tutorial part 1
13:45
Thomas Langhorst
Рет қаралды 12 М.
Be kind🤝
00:22
ISSEI / いっせい
Рет қаралды 20 МЛН
КАК СПРЯТАТЬ КОНФЕТЫ
00:59
123 GO! Shorts Russian
Рет қаралды 3 МЛН
100❤️
00:19
Nonomen ノノメン
Рет қаралды 38 МЛН
Rust Tests Itself (kind of!)
11:41
No Boilerplate
Рет қаралды 76 М.
Unit testing in golang - a beginners + advanced-ish tutorial
13:12
Thomas Langhorst
Рет қаралды 7 М.
The standard library now has all you need for advanced routing in Go.
13:52
Tutorial: Do you really think you understand Go interfaces?
11:38
Learn Go Programming
Рет қаралды 63 М.
Mastering Dependency Injection In Golang
14:29
Anthony GG
Рет қаралды 42 М.
Go 1.22 is bringing about a new future for the language.
4:32
Dreams of Code
Рет қаралды 144 М.
Golang / Go Crash Course 04 | Unit testing our code by Mocking with Testify
31:41
Advanced Testing in Go
16:03
TutorialEdge
Рет қаралды 51 М.
[1/5] Building a CLI Kanban Board with Bubble Tea
18:09
Charm CLI
Рет қаралды 40 М.
Kalem ile Apple Pen Nasıl Yapılır?😱
0:20
Safak Novruz
Рет қаралды 1,2 МЛН
как спасти усилитель?
0:35
KS Customs
Рет қаралды 514 М.
Latest Nokia Mobile Phone
0:42
Tech Official
Рет қаралды 491 М.