November 2018
Intermediate to advanced
346 pages
8h 12m
English
Despite being a small and working service, we have quite a few issues, perhaps the most egregious of which is its difficulty to test. Now, we don't want to start introducing test-induced damage, but we do want to have a system that we are confident in. To achieve this, we are going to need to reduce the complexity and verbosity of the tests. Take a look at the following test:
func TestGetHandler_ServeHTTP(t *testing.T) { // ensure the test always fails by giving it a timeout ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() // Create and start a server // With out current implementation, we cannot test this handler // without a full server as we need the mux. address, err := startServer(ctx) ...
Read now
Unlock full access