Unit Testing a Web App
Learn to write unit tests to test the business logic and handlers for our web app.
We'll cover the following...
Unit testing
In earlier lessons, we created the package coffee
for our app, which has the functions to list the coffee menu and to check if a particular type of coffee is available.
Let's try to test the latter function using unit tests. For this, we'll create a file called coffee_test.go
under the coffee
directory. The structure of the project becomes the following:
coffeeshop|__ go.mod|__ go.sum|__ config.json|__ coffee|__ coffee.go|__ coffee_test.go|__ templates|__ index.html
Project structure so far
The file ...