andriajah Mon Jan 2023 1 year ago

Golang Unit Testing And Mock Testing Tutorial

In this video we are going to learn what a unit test and what mocking and stubs are. We learn how to create go files for testing, using the testing library, and set up basic unit tests plus using a slice to run a multitude of tests.

We also use the httptest package to set up a mock server to mimic getting JSON data from the web. So that we learn how to do mock testing in golang. There are a lot of different ways to do mock testing, in this tutorial we set up a simple mock test using a stub server to return JSON data for testing.

More information on the loop back interface:
https://en.wikipedia.org/wiki/Loopback#Virtual_loopback_interface

More information on the net/http/httptest package:
https://pkg.go.dev/net/http/httptest

If you wanna support my channel, you can buy me a coffee:
☕️ https://www.buymeacoffee.com/nerdcademy
Coffee make the code go!!!

💻 Programming Laptop
https://kit.co/nerdcademy/framework-laptop

🎥 My Video Kit
https://kit.co/nerdcademy/my-video-kit

🖥 Video Editing PC
https://kit.co/nerdcademy/m1-mac-mini-setup

All code found in this video will be at:
💻 https://github.com/NerdCademyDev/golang

🎨 Gopher Character artwork from:
https://github.com/MariaLetta/free-gophers-pack

#golang #unittesting #nerdcademy
go mock testing go mock testing tutorial go programming go programming language go programming tutorial go tutorial go unit testing go unit testing tutorial golang httptest golang mock testing golang mock testing tutorial golang programming golang programming tutorial golang tutorial golang tutorials golang unit testing golang unit testing tutorial programming programming tutorial software developer software development software development tutorial