From the course: Consuming RESTful APIs in Golang

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Unit testing API calls

Unit testing API calls

- [Instructor] In the previous videos, we looked at all the different things we could do with HTTP client, marshaling, unmarshaling, responses, manipulating the request and all kinds of things. But in this video we want to take it a step higher and make things a bit more practical, want to look at unit testing. Now, unit testing is a very important part of software development, and put simply, unit testing is the practice where you validate the behavior of your code. You test units or components of your program in isolation to ensure they function correctly and they meet the expected behavior. Now, I'm sure at this point you're probably wondering how this could be done with HTTP clients because in the first place your HTTP clients are talking to real APIs. So what are we saying? Are you going to be talking to real APIs in your unit test? Not really, once again, the Golang robust net/http package comes to your rescue. Now the net/http package has a package or a subpackage called…

Contents