Interfaces 101 : Testing with a Mock Interface

Published: 20 March 2023
on channel: Ardan Labs
6,866
85

Episode 8! - Watch and learn how to mock server responses for unit tests. -- In this video, Miki will build an API client type for a web service. The type will have a method called `Health` that:
Performs an HTTP request to a URL.
Returns an error depending on the response code received from the server.
Miki will then proceed by writing unit tests to verify if the client is working as intended. In lieu of a real server, Miki will create a new type that implements the `http.RoundTripper` interface and use it as the request’s transport during testing to manually specify the response code returned.


Things you will learn in this video
Perform an HTTP request with the Go STD library.
Mock an HTTP response for unit tests.


For the full course materials visit → https://github.com/ardanlabs/gotraini...

--

Which aspects of your tests do you mock by taking advantage of Go interfaces?
Comment below or tweet us on twitter & let us know, we want to hear from you! ~ If you found this video helpful, hit that like button & subscribe for more content like this.

--

Access our online courses → https://ardanlabs.com/education

Attending a live training → https://www.ardanlabs.com/live-traini...

Other Links:
Website: https://www.ardanlabs.com/
Github: https://github.com/ardanlabs
Twitter:   / ardanlabs  


On this page of the site you can watch the video online Interfaces 101 : Testing with a Mock Interface with a duration of hours minute second in good quality, which was uploaded by the user Ardan Labs 20 March 2023, share the link with friends and acquaintances, this video has already been watched 6,866 times on youtube and it was liked by 85 viewers. Enjoy your viewing!