How it works...

Execute a go test from the command line as follows:

$ go test websocket-server_test.go websocket-server.gook  command-line-arguments 0.048s

It will give us the response ok, which means the test compiled and executed successfully.

Let’s see how it looks when a Go test fails. Change the expected output in the assert statement to something else. In the following hello has been changed to hi:

...assert.Equal(t, "hi", message.Message, "they should be equal")...

Execute the test again by running the go test command:

$ go test websocket-server_test.go websocket-server.go

It will give us the failure response along with the error trace as shown in the following screenshot:

Get Go Web Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.