Testing best practices
In this section, we are going to list some additional useful testing tips that are going to help you to improve the quality of your tests.
Using helpful messages
One of the most important aspects of writing tests is providing enough information in error logs that it is easy to understand exactly what went wrong and which test case triggered the failure. Consider the following test case code:
if got, want := Process(tt.in), tt.want; got != want {
t.Errorf("Result mismatch")
}
The error log does not include both the expected and the actual value received from the function being tested, making it harder to understand what the function returned and how it was different from the expected value.
The better log line would be as follows:
t.Errorf("got %v, want %v", got, want)
This log line includes the expected and the actual returned value of the function and provides much more context to you when you debug the test...