November 2018
Intermediate to advanced
346 pages
8h 12m
English
Writing automated tests can feel like extra work, something that takes time away from our real purpose of writing features. In fact, the primary goal of automated tests is to ensure that code performs as expected, and continues to do so despite any changes or additions we might make to the code base as a whole. Automated tests do, however, have a cost: you have to write and maintain them. Therefore, if our code is easy to test, we will be less inclined to skimp on the tests and rush on to that exciting next feature.
Let's look at an example, as shown in the following code:
func longMethod(resp http.ResponseWriter, req *http.Request) { err := req.ParseForm() if err != nil { resp.WriteHeader(http.StatusPreconditionFailed)
Read now
Unlock full access