November 2018
Intermediate to advanced
346 pages
8h 12m
English
Another problem that could arise is excessive test coverage. Yes, you read that right. Writing too many tests is possible. Programmers, being the technically minded folks that we are, love metrics. Unit-test coverage is one such metric. While it is possible to achieve 100% test coverage, realizing this goal is a huge time sink, and the resulting code can be rather terrible. Consider the following code:
func WriteAndClose(destination io.WriteCloser, contents string) error { defer destination.Close() _, err := destination.Write([]byte(contents)) if err != nil { return err } return nil }
To achieve 100% coverage, we would have to write a test where the destination.Close() call fails. We can totally do this, but what ...
Read now
Unlock full access