These days writing automated tests for your software is just as important as any other phase in the development life cycle.
In this article, I’ll go over how I write unit tests for HTTP servers in Go.
To make testing easier, I’ll be using the stretchr/testify, which gives access to many testing utils.
After initializing your go project, run the following command to install the testing library:
$ go get -u github.com/stretchr/testify
An http.HandlerFunc is a function that will be called when a request hits its corresponding endpoint, and has the following signature:
type HandlerFunc func(ResponseWriter, *Request)
In this example…
Testing is just as important as any other phase of the software development life cycle, yet many developers tend to neglect it.
In this article, I’ll go through the implementation of some simple unit tests for a small Flask application that supports two routes.
The Flask application I’ll be writing tests for can be found in this repo: https://github.com/ElMehdi19/flask-schema-example
After cloning the repo, setting up a virtual environment, and installing the requirements, let’s now install Pytest:
$ pip3 install pytest
Let’s now create a new folder in the root of the project where our tests will live:
$ mkdir testing